Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration.ConfigurationSettings
Imports System.Diagnostics

Namespace DAOMain

#Region "CommonDAO"
    Public Class CommonDAO
        Public g_strConnection As String = ""
        Private g_txnCommit As OleDbTransaction = Nothing
        Private ParamValues As Collection

        Protected Enum QueryType As Byte
            SelectType = 0
            UpdateType = 1
            InsertType = 2
            DeleteType = 3
        End Enum

        Public Property Transaction() As OleDbTransaction
            Get
                Return g_txnCommit
            End Get
            Set(ByVal Value As OleDbTransaction)
                g_txnCommit = Value
            End Set
        End Property

        Protected Property ConnectionString() As String
            Get
                Return g_strConnection
            End Get
            Set(ByVal Value As String)
                g_strConnection = Value
            End Set
        End Property

        Public Sub New()
            g_strConnection = AppSettings("OledbCnnStr")
            ParamValues = New Collection
        End Sub

        Public Sub AddParameter(ByVal strParam)
            ParamValues.Add(strParam)
        End Sub

        Public Function ExecQuery(ByVal CommandString As String) As DataTable
            Dim Cnn As New OleDbConnection
            Dim Cmd As New OleDbCommand
            Dim dt As New DataTable

            Try
                Cnn.ConnectionString = g_strConnection
                Cnn.Open()

                Cmd.Connection = Cnn
                Cmd.CommandType = CommandType.Text
                Cmd.CommandText = CommandString

                Dim da As New OleDbDataAdapter(Cmd)
                da.Fill(dt)

            Catch ex As Exception

            Finally
                Cnn.Close()
            End Try

            Return dt

            Cmd = Nothing
            Cnn = Nothing
        End Function

        Public Function ExecCommandWithTrapping(ByVal CommandString As String) As String
            Dim Cnn As New OleDbConnection
            Dim Cmd As New OleDbCommand
            Dim strReturn As String = "Successful"

            Try
                Cnn.ConnectionString = g_strConnection
                Cnn.Open()

                Cmd.Connection = Cnn
                Cmd.CommandType = CommandType.Text
                Cmd.CommandText = CommandString

                Dim dr As OleDbDataReader

                dr = Cmd.ExecuteReader()

            Catch ex As Exception
                strReturn = ex.Message
            Finally
                Cnn.Close()
            End Try

            Return strReturn

            Cmd = Nothing
            Cnn = Nothing
        End Function

        Public Function ExecCommand(ByVal CommandString As String) As Boolean
            Dim Cnn As New OleDbConnection
            Dim Cmd As New OleDbCommand
            Dim bln As Boolean = True

            Try
                Cnn.ConnectionString = g_strConnection
                Cnn.Open()

                Cmd.Connection = Cnn
                Cmd.CommandType = CommandType.Text
                Cmd.CommandText = CommandString

                Dim dr As OleDbDataReader

                dr = Cmd.ExecuteReader()

            Catch ex As Exception
                bln = False
            Finally
                Cnn.Close()
            End Try

            Return bln

            Cmd = Nothing
            Cnn = Nothing
        End Function

        Private Function GetParamNames(ByVal ProcName As String) As Collection
            Dim Cnn As New OleDbConnection
            Dim Cmd As New OleDbCommand
            Dim ParamNames As New Collection

            Try
                Cnn.ConnectionString = g_strConnection
                Cnn.Open()

                Cmd.Connection = Cnn
                Cmd.CommandType = CommandType.Text
                Cmd.CommandText = "SELECT * From vw_proc_list  WHERE sp_name = " & Q(ProcName) & " ORDER by colorder"

                Dim dr As OleDbDataReader

                dr = Cmd.ExecuteReader()

                While dr.Read
                    ParamNames.Add(dr.Item("param_name"))
                End While
            Catch ex As Exception

            Finally
                Cnn.Close()
            End Try

            Return ParamNames

            ParamNames = Nothing
            Cmd = Nothing
            Cnn = Nothing
        End Function

        Public Function ExecQryProc(ByVal ProcName As String, _
                            Optional ByVal useFillTable As Boolean = False) As DataTable

            Dim dt As New DataTable

            Dim ParamNames As New Collection
            Dim Cnn As New OleDbConnection
            Dim Cmd As New OleDbCommand

            ParamNames = GetParamNames(ProcName)

            If ParamNames.Count = ParamValues.Count Then
                Try
                    Cnn.ConnectionString = g_strConnection

                    Cnn.Open()
                    Cmd.CommandTimeout = 300
                    Cmd.Connection = Cnn
                    Cmd.CommandType = CommandType.StoredProcedure
                    Cmd.CommandText = ProcName

                    ParamBuilder(ProcName, Cmd, ParamNames, ParamValues)

                    If useFillTable Then
                        Dim dr As OleDbDataReader

                        dr = Cmd.ExecuteReader()
                        dt = FillDataTable(dr)
                    Else
                        Dim da As New OleDbDataAdapter(Cmd)
                        da.Fill(dt)
                    End If

                Catch ex As Exception

                Finally
                    Cnn.Close()
                End Try
            End If

            Cmd = Nothing
            Cnn = Nothing
            ParamNames = Nothing

            Return dt
        End Function

        Public Function ExecCmdProc(ByVal ProcName As String) As Boolean
            Dim blnSuccess As Boolean = True

            Dim ParamNames As New Collection
            Dim Cnn As New OleDbConnection
            Dim Cmd As New OleDbCommand

            ParamNames = GetParamNames(ProcName)

            If ParamNames.Count = ParamValues.Count Then
                Try
                    Cnn.ConnectionString = g_strConnection

                    Cnn.Open()
                    Cmd.Connection = Cnn
                    Cmd.CommandType = CommandType.StoredProcedure
                    Cmd.CommandText = ProcName
                    Cmd.CommandTimeout = 600

                    ParamBuilder(ProcName, Cmd, ParamNames, ParamValues)

                    Cmd.ExecuteNonQuery()

                Catch ex As Exception
                    blnSuccess = False
                Finally
                    Cnn.Close()
                End Try
            Else
                blnSuccess = False
            End If

            Cmd = Nothing
            Cnn = Nothing
            ParamNames = Nothing

            Return blnSuccess
        End Function

        Private Sub ParamBuilder(ByVal ProcName As String, ByVal Cmd As OleDbCommand, _
                                        ByVal ParamNames As Collection, ByVal ParamValues As Collection)
            Dim i As Short

            With Cmd.Parameters
                For i = 1 To ParamNames.Count
                    Dim tParam As New OleDbParameter

                    tParam.ParameterName = ParamNames.Item(i).ToString
                    tParam.Value = ParamValues.Item(i)

                    .Add(tParam)

                    tParam = Nothing
                Next

            End With
        End Sub

        Public Function Q(ByVal mStr As String)
            Dim mStr1 As String
            Dim mIn1 As Short
            mStr1 = mStr
            Q = ""
            Do While True
                mIn1 = InStr(mStr1, "'")
                If mIn1 <> 0 Then
                    Q = Q + Left(mStr1, mIn1) + "'"
                    mStr1 = Mid(mStr1, mIn1 + 1)
                Else
                    Exit Do
                End If
            Loop
            Q = "'" + Q + mStr1 + "'"
        End Function

        Public Function FillDataTable(ByRef dataReader As IDataReader, Optional ByVal AddCols As Integer = 0) As DataTable
            Dim i As Integer
            Dim intNumCols As Integer
            Dim dataTable As New DataTable
            Dim dtCols As New DataTable
            Dim drow As DataRow
            Dim strColName As String
            '
            'Insert datareader schema into datatable(dtCols)
            dtCols = dataReader.GetSchemaTable()
            intNumCols = dtCols.Rows.Count - 1
            '
            'Loop thru dtCols, inserting columns into dataTable
            For i = 0 To intNumCols
                strColName = dtCols.Rows(i)("ColumnName")
                dataTable.Columns.Add(strColName) 'dtCols.Rows(i)("DataType"))
            Next

            'Iterate thru datareader, adding rows to datatable
            While dataReader.Read
                drow = dataTable.NewRow
                'Iterate thru columns datatable
                For i = 0 To intNumCols
                    drow(i) = dataReader(dtCols.Rows(i)("ColumnName").ToString)
                Next
                dataTable.Rows.Add(drow)
            End While
            '
            dataReader.Close()
            dtCols.Rows.Clear()
            '
            Return dataTable
            '
        End Function

        Friend Function CheckBit(ByVal Value As Long, ByVal MaskValue As Long) As Boolean
            If Value < 0 Then Exit Function

            If (Value And MaskValue) = MaskValue Then
                Return True
            Else
                Return False
            End If
        End Function


        Protected Overrides Sub Finalize()
            ParamValues = Nothing
            MyBase.Finalize()
        End Sub
    End Class
#End Region

#Region "vw_policy_trans"

    <Serializable()> _
    Public Class VW_POLICY_TRANS_SEARCH_VO

        Public POLICY_SEQ_CD As String
        Public POLICY_NO As String
        Public BROKER_DESC As String
        Public PRDT_DESC As String
        Public PROVIDER_DESC As String
        Public POLICY_CLIENT_LAST_NAME As String
        Public POLICY_CLIENT_FIRST_NAME As String
        Public POLICY_CLIENT_MIDDLE_NAME As String
        Public POLICY_CLIENT_ALIAS As String
        Public PROCESS_ST As String
        Public CONTRIBUTION_AMT As Integer = -1
        Public CURRENCY_CD As String
        Public ADVISOR As String

        Public Enum Enum_VW_POLICY_TRANS_SEARCH As Short
            NONE = 0
            policy_seq_cd = 1
            policy_no = 2
            broker_desc = 4
            prdt_desc = 8
            provider_desc = 16
            policy_client_last_name = 32
            policy_client_first_name = 64
            policy_client_middle_name = 128
            policy_client_alias = 256
            process_st = 512
            contribution_amt = 1024
            currency_cd = 2048
            advisor = 4096
        End Enum

    End Class

    Public Class VW_POLICY_TRANS_SEARCH_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_policy_trans_search_VO, Optional ByVal ExcludeValue As vw_policy_trans_search_VO.Enum_vw_policy_trans_search = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT distinct [policy_seq_cd] ,[policy_no] ,[broker_desc] ,[prdt_desc] ,[provider_desc] ,[process_st] ,[contribution_amt] ,[currency_cd] ,[advisor] FROM vw_policy_trans_search " _
                        & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike) _
                        & " ORDER BY [broker_desc], [policy_no] ,[provider_desc] ,[prdt_desc] " 'JCP 26-Jun-2012: #0000006 
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_TRANS_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search = VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_SEQ_CD
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_NO
                If Not isnothing(.BROKER_DESC) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.BROKER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.PRDT_DESC
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.PROVIDER_DESC
                If Not isnothing(.POLICY_CLIENT_LAST_NAME) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_LAST_NAME
                If Not isnothing(.POLICY_CLIENT_FIRST_NAME) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_FIRST_NAME
                If Not isnothing(.POLICY_CLIENT_MIDDLE_NAME) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_MIDDLE_NAME
                If Not isnothing(.POLICY_CLIENT_ALIAS) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_ALIAS
                If Not isnothing(.PROCESS_ST) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.PROCESS_ST
                If .CONTRIBUTION_AMT >= 0 Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.CONTRIBUTION_AMT
                If Not isnothing(.CURRENCY_CD) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.CURRENCY_CD
                If Not isnothing(.ADVISOR) Then shrtFlag += VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.ADVISOR
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_policy_trans_search SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_policy_trans_search (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_policy_trans_search WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.BROKER_DESC) Then
                            .Append("BROKER_DESC")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.BROKER_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_LAST_NAME) Then
                            .Append("POLICY_CLIENT_LAST_NAME")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_LAST_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_FIRST_NAME) Then
                            .Append("POLICY_CLIENT_FIRST_NAME")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_FIRST_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_MIDDLE_NAME) Then
                            .Append("POLICY_CLIENT_MIDDLE_NAME")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_MIDDLE_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_ALIAS) Then
                            .Append("POLICY_CLIENT_ALIAS")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_ALIAS

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.PROCESS_ST) Then
                            .Append("PROCESS_ST")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.PROCESS_ST

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.CONTRIBUTION_AMT) Then
                            .Append("CONTRIBUTION_AMT")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.CONTRIBUTION_AMT

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.CURRENCY_CD) Then
                            .Append("CURRENCY_CD")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.CURRENCY_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.ADVISOR) Then
                            .Append("ADVISOR")
                            shrtFlag -= VW_POLICY_TRANS_SEARCH_VO.Enum_vw_policy_trans_search.ADVISOR

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            '.Append(";") 'JCP 26-Jun-2012: #0000006 

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_policy_trans_search_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_policy_trans_search_VO.Enum_vw_policy_trans_search = vw_policy_trans_search_VO.Enum_vw_policy_trans_search.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.BROKER_DESC) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.BROKER_DESC) Then .AddWithValue("@broker_desc", Value.BROKER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.POLICY_CLIENT_LAST_NAME) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_LAST_NAME) Then .AddWithValue("@policy_client_last_name", Value.POLICY_CLIENT_LAST_NAME)
                If Not isnothing(Value.POLICY_CLIENT_FIRST_NAME) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_FIRST_NAME) Then .AddWithValue("@policy_client_first_name", Value.POLICY_CLIENT_FIRST_NAME)
                If Not isnothing(Value.POLICY_CLIENT_MIDDLE_NAME) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_MIDDLE_NAME) Then .AddWithValue("@policy_client_middle_name", Value.POLICY_CLIENT_MIDDLE_NAME)
                If Not isnothing(Value.POLICY_CLIENT_ALIAS) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_ALIAS) Then .AddWithValue("@policy_client_alias", Value.POLICY_CLIENT_ALIAS)
                If Not isnothing(Value.PROCESS_ST) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.PROCESS_ST) Then .AddWithValue("@process_st", Value.PROCESS_ST)
                If Value.CONTRIBUTION_AMT >= 0 And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.CONTRIBUTION_AMT) Then .AddWithValue("@contribution_amt", Value.CONTRIBUTION_AMT)
                If Not isnothing(Value.CURRENCY_CD) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.CURRENCY_CD) Then .AddWithValue("@currency_cd", Value.CURRENCY_CD)
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.ADVISOR) Then .AddWithValue("@advisor", Value.ADVISOR)
            End With
        End Sub
        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As vw_policy_trans_search_VO, Optional ByVal ExcludeValue As vw_policy_trans_search_VO.Enum_vw_policy_trans_search = vw_policy_trans_search_VO.Enum_vw_policy_trans_search.None)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_SEQ_CD) Then .Add("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_NO) Then .Add("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.BROKER_DESC) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.BROKER_DESC) Then .Add("@broker_desc", Value.BROKER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.PRDT_DESC) Then .Add("@prdt_desc", Value.PRDT_DESC)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.PROVIDER_DESC) Then .Add("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.POLICY_CLIENT_LAST_NAME) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_LAST_NAME) Then .Add("@policy_client_last_name", Value.POLICY_CLIENT_LAST_NAME)
                If Not isnothing(Value.POLICY_CLIENT_FIRST_NAME) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_FIRST_NAME) Then .Add("@policy_client_first_name", Value.POLICY_CLIENT_FIRST_NAME)
                If Not isnothing(Value.POLICY_CLIENT_MIDDLE_NAME) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_MIDDLE_NAME) Then .Add("@policy_client_middle_name", Value.POLICY_CLIENT_MIDDLE_NAME)
                If Not isnothing(Value.POLICY_CLIENT_ALIAS) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.POLICY_CLIENT_ALIAS) Then .Add("@policy_client_alias", Value.POLICY_CLIENT_ALIAS)
                If Not isnothing(Value.PROCESS_ST) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.PROCESS_ST) Then .Add("@process_st", Value.PROCESS_ST)
                If Value.CONTRIBUTION_AMT >= 0 And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.CONTRIBUTION_AMT) Then .Add("@contribution_amt", Value.CONTRIBUTION_AMT)
                If Not isnothing(Value.CURRENCY_CD) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.CURRENCY_CD) Then .Add("@currency_cd", Value.CURRENCY_CD)
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_policy_trans_search_VO.Enum_vw_policy_trans_search.ADVISOR) Then .Add("@advisor", Value.ADVISOR)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As vw_policy_trans_search_VO, Optional ByVal ExcludeValue As vw_policy_trans_search_VO.Enum_vw_policy_trans_search = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_policy_trans_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "vw_policy_client_dtl"

    <Serializable()> _
    Public Class VW_POLICY_CLIENT_DTL_VO

        Public POLICY_CLIENT_CD As String
        Public POLICY_SEQ_CD As String
        Public NAME As String
        Public EMAIL_ADDRESS As String
        Public TEL_NO As String
        Public FAX_NO As String
        Public MOBILE_NO As String
        Public INSURED_TAG As Integer = -1
        Public OWNER_TAG As Integer = -1

        Public Enum Enum_VW_POLICY_CLIENT_DTL As Short
            NONE = 0
            policy_client_cd = 1
            policy_seq_cd = 2
            Name = 4
            email_address = 8
            tel_no = 16
            fax_no = 32
            mobile_no = 64
            insured_tag = 128
            owner_tag = 256
        End Enum

    End Class

    Public Class VW_POLICY_CLIENT_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As VW_POLICY_CLIENT_DTL_VO, Optional ByVal ExcludeValue As VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM VW_POLICY_CLIENT_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_CLIENT_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL = VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.POLICY_CLIENT_CD) Then shrtFlag += VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.policy_client_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.policy_seq_cd
                If Not IsNothing(.NAME) Then shrtFlag += VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.Name
                If Not IsNothing(.EMAIL_ADDRESS) Then shrtFlag += VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.email_address
                If Not IsNothing(.TEL_NO) Then shrtFlag += VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.tel_no
                If Not IsNothing(.FAX_NO) Then shrtFlag += VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.fax_no
                If Not IsNothing(.MOBILE_NO) Then shrtFlag += VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.mobile_no
                If .INSURED_TAG >= 0 Then shrtFlag += VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.insured_tag
                If .OWNER_TAG >= 0 Then shrtFlag += VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.owner_tag
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE VW_POLICY_CLIENT_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO VW_POLICY_CLIENT_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM VW_POLICY_CLIENT_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.policy_client_cd) Then
                            .Append("POLICY_CLIENT_CD")
                            shrtFlag -= VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.policy_client_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.Name) Then
                            .Append("NAME")
                            shrtFlag -= VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.Name

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.email_address) Then
                            .Append("EMAIL_ADDRESS")
                            shrtFlag -= VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.email_address

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.tel_no) Then
                            .Append("TEL_NO")
                            shrtFlag -= VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.tel_no

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.fax_no) Then
                            .Append("FAX_NO")
                            shrtFlag -= VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.fax_no

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.mobile_no) Then
                            .Append("MOBILE_NO")
                            shrtFlag -= VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.mobile_no

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.insured_tag) Then
                            .Append("INSURED_TAG")
                            shrtFlag -= VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.insured_tag

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.owner_tag) Then
                            .Append("OWNER_TAG")
                            shrtFlag -= VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.owner_tag

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As VW_POLICY_CLIENT_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL = VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_CLIENT_CD) And Not CheckBit(ExcludeValue, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.policy_client_cd) Then .AddWithValue("@policy_client_cd", Value.POLICY_CLIENT_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.NAME) And Not CheckBit(ExcludeValue, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.Name) Then .AddWithValue("@Name", Value.NAME)
                If Not IsNothing(Value.EMAIL_ADDRESS) And Not CheckBit(ExcludeValue, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.email_address) Then .AddWithValue("@email_address", Value.EMAIL_ADDRESS)
                If Not IsNothing(Value.TEL_NO) And Not CheckBit(ExcludeValue, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.tel_no) Then .AddWithValue("@tel_no", Value.TEL_NO)
                If Not IsNothing(Value.FAX_NO) And Not CheckBit(ExcludeValue, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.fax_no) Then .AddWithValue("@fax_no", Value.FAX_NO)
                If Not IsNothing(Value.MOBILE_NO) And Not CheckBit(ExcludeValue, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.mobile_no) Then .AddWithValue("@mobile_no", Value.MOBILE_NO)
                If Value.INSURED_TAG >= 0 And Not CheckBit(ExcludeValue, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.insured_tag) Then .AddWithValue("@insured_tag", Value.INSURED_TAG)
                If Value.OWNER_TAG >= 0 And Not CheckBit(ExcludeValue, VW_POLICY_CLIENT_DTL_VO.Enum_VW_POLICY_CLIENT_DTL.owner_tag) Then .AddWithValue("@owner_tag", Value.OWNER_TAG)
            End With
        End Sub
    End Class

#End Region

#Region "vw_policy_bene_dtl"

    <Serializable()> _
    Public Class VW_POLICY_BENE_DTL_VO

        Public POLICY_BENE_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_BENE_LAST_NAME As String
        Public POLICY_BENE_FIRST_NAME As String
        Public POLICY_BENE_MIDDLE_NAME As String
        Public RANKING As String
        Public SHARE As Integer = -1
        Public RELATIONSHIP As String

        Public Enum Enum_VW_POLICY_BENE_DTL As Short
            NONE = 0
            policy_bene_cd = 1
            policy_seq_cd = 2
            policy_bene_last_name = 4
            policy_bene_first_name = 8
            policy_bene_middle_name = 16
            ranking = 32
            share = 64
            relationship = 128
        End Enum

    End Class

    Public Class VW_POLICY_BENE_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As VW_POLICY_BENE_DTL_VO, Optional ByVal ExcludeValue As VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM VW_POLICY_BENE_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_BENE_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL = VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.POLICY_BENE_CD) Then shrtFlag += VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_SEQ_CD
                If Not isnothing(.POLICY_BENE_LAST_NAME) Then shrtFlag += VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_LAST_NAME
                If Not isnothing(.POLICY_BENE_FIRST_NAME) Then shrtFlag += VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_FIRST_NAME
                If Not isnothing(.POLICY_BENE_MIDDLE_NAME) Then shrtFlag += VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_MIDDLE_NAME
                If Not isnothing(.RANKING) Then shrtFlag += VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.RANKING
                If .SHARE >= 0 Then shrtFlag += VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.SHARE
                If Not isnothing(.RELATIONSHIP) Then shrtFlag += VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.RELATIONSHIP
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE VW_POLICY_BENE_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO VW_POLICY_BENE_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM VW_POLICY_BENE_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_CD) Then
                            .Append("POLICY_BENE_CD")
                            shrtFlag -= VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_LAST_NAME) Then
                            .Append("POLICY_BENE_LAST_NAME")
                            shrtFlag -= VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_LAST_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_FIRST_NAME) Then
                            .Append("POLICY_BENE_FIRST_NAME")
                            shrtFlag -= VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_FIRST_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_MIDDLE_NAME) Then
                            .Append("POLICY_BENE_MIDDLE_NAME")
                            shrtFlag -= VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_MIDDLE_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.RANKING) Then
                            .Append("RANKING")
                            shrtFlag -= VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.RANKING

                        ElseIf CheckBit(shrtFlag, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.SHARE) Then
                            .Append("SHARE")
                            shrtFlag -= VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.SHARE

                        ElseIf CheckBit(shrtFlag, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.RELATIONSHIP) Then
                            .Append("RELATIONSHIP")
                            shrtFlag -= VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.RELATIONSHIP

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As VW_POLICY_BENE_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL = VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_BENE_CD) And Not CheckBit(ExcludeValue, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_CD) Then .AddWithValue("@policy_bene_cd", Value.POLICY_BENE_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.POLICY_BENE_LAST_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_LAST_NAME) Then .AddWithValue("@policy_bene_last_name", Value.POLICY_BENE_LAST_NAME)
                If Not isnothing(Value.POLICY_BENE_FIRST_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_FIRST_NAME) Then .AddWithValue("@policy_bene_first_name", Value.POLICY_BENE_FIRST_NAME)
                If Not isnothing(Value.POLICY_BENE_MIDDLE_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.POLICY_BENE_MIDDLE_NAME) Then .AddWithValue("@policy_bene_middle_name", Value.POLICY_BENE_MIDDLE_NAME)
                If Not isnothing(Value.RANKING) And Not CheckBit(ExcludeValue, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.RANKING) Then .AddWithValue("@ranking", Value.RANKING)
                If Value.SHARE >= 0 And Not CheckBit(ExcludeValue, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.SHARE) Then .AddWithValue("@share", Value.SHARE)
                If Not isnothing(Value.RELATIONSHIP) And Not CheckBit(ExcludeValue, VW_POLICY_BENE_DTL_VO.Enum_VW_POLICY_BENE_DTL.RELATIONSHIP) Then .AddWithValue("@relationship", Value.RELATIONSHIP)
            End With
        End Sub
    End Class


#End Region

#Region "vw_policy_trustees_dtl"

    <Serializable()> _
    Public Class VW_POLICY_TRUSTEES_DTL_VO

        Public POLICY_TRUSTEES_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_TRUSTEES_LAST_NAME As String
        Public POLICY_TRUSTEES_FIRST_NAME As String
        Public POLICY_TRUSTEES_MIDDLE_NAME As String
        Public RELATIONSHIP As String
        Public RANKING As String

        Public Enum Enum_VW_POLICY_TRUSTEES_DTL As Short
            NONE = 0
            policy_trustees_cd = 1
            policy_seq_cd = 2
            policy_trustees_last_name = 4
            policy_trustees_first_name = 8
            policy_trustees_middle_name = 16
            relationship = 32
            ranking = 64
        End Enum

    End Class

    Public Class VW_POLICY_TRUSTEES_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As VW_POLICY_TRUSTEES_DTL_VO, Optional ByVal ExcludeValue As VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM VW_POLICY_TRUSTEES_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_TRUSTEES_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL = VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.POLICY_TRUSTEES_CD) Then shrtFlag += VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_SEQ_CD
                If Not isnothing(.POLICY_TRUSTEES_LAST_NAME) Then shrtFlag += VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_LAST_NAME
                If Not isnothing(.POLICY_TRUSTEES_FIRST_NAME) Then shrtFlag += VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_FIRST_NAME
                If Not isnothing(.POLICY_TRUSTEES_MIDDLE_NAME) Then shrtFlag += VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_MIDDLE_NAME
                If Not isnothing(.RELATIONSHIP) Then shrtFlag += VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.RELATIONSHIP
                If Not isnothing(.RANKING) Then shrtFlag += VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.RANKING
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE VW_POLICY_TRUSTEES_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO VW_POLICY_TRUSTEES_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM VW_POLICY_TRUSTEES_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_CD) Then
                            .Append("POLICY_TRUSTEES_CD")
                            shrtFlag -= VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_LAST_NAME) Then
                            .Append("POLICY_TRUSTEES_LAST_NAME")
                            shrtFlag -= VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_LAST_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_FIRST_NAME) Then
                            .Append("POLICY_TRUSTEES_FIRST_NAME")
                            shrtFlag -= VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_FIRST_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_MIDDLE_NAME) Then
                            .Append("POLICY_TRUSTEES_MIDDLE_NAME")
                            shrtFlag -= VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_MIDDLE_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.RELATIONSHIP) Then
                            .Append("RELATIONSHIP")
                            shrtFlag -= VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.RELATIONSHIP

                        ElseIf CheckBit(shrtFlag, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.RANKING) Then
                            .Append("RANKING")
                            shrtFlag -= VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.RANKING

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As VW_POLICY_TRUSTEES_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL = VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_TRUSTEES_CD) And Not CheckBit(ExcludeValue, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_CD) Then .AddWithValue("@policy_trustees_cd", Value.POLICY_TRUSTEES_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.POLICY_TRUSTEES_LAST_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_LAST_NAME) Then .AddWithValue("@policy_trustees_last_name", Value.POLICY_TRUSTEES_LAST_NAME)
                If Not isnothing(Value.POLICY_TRUSTEES_FIRST_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_FIRST_NAME) Then .AddWithValue("@policy_trustees_first_name", Value.POLICY_TRUSTEES_FIRST_NAME)
                If Not isnothing(Value.POLICY_TRUSTEES_MIDDLE_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.POLICY_TRUSTEES_MIDDLE_NAME) Then .AddWithValue("@policy_trustees_middle_name", Value.POLICY_TRUSTEES_MIDDLE_NAME)
                If Not isnothing(Value.RELATIONSHIP) And Not CheckBit(ExcludeValue, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.RELATIONSHIP) Then .AddWithValue("@relationship", Value.RELATIONSHIP)
                If Not isnothing(Value.RANKING) And Not CheckBit(ExcludeValue, VW_POLICY_TRUSTEES_DTL_VO.Enum_VW_POLICY_TRUSTEES_DTL.RANKING) Then .AddWithValue("@ranking", Value.RANKING)
            End With
        End Sub
    End Class

#End Region

#Region "vw_policy_prem_rider_dtl"

    <Serializable()> _
    Public Class VW_POLICY_PREM_RIDER_DTL_VO

        Public PREM_RIDER_CD As String
        Public POLICY_SEQ_CD As String
        Public PREM_RIDER_DESC As String
        Public BENEFITS As Integer = -1

        Public Enum Enum_VW_POLICY_PREM_RIDER_DTL As Short
            NONE = 0
            prem_rider_cd = 1
            policy_seq_cd = 2
            prem_rider_desc = 4
            benefits = 8
        End Enum

    End Class

    Public Class VW_POLICY_PREM_RIDER_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As VW_POLICY_PREM_RIDER_DTL_VO, Optional ByVal ExcludeValue As VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM VW_POLICY_PREM_RIDER_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_PREM_RIDER_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL = VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.PREM_RIDER_CD) Then shrtFlag += VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.PREM_RIDER_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.POLICY_SEQ_CD
                If Not isnothing(.PREM_RIDER_DESC) Then shrtFlag += VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.PREM_RIDER_DESC
                If .BENEFITS >= 0 Then shrtFlag += VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.BENEFITS
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE VW_POLICY_PREM_RIDER_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO VW_POLICY_PREM_RIDER_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM VW_POLICY_PREM_RIDER_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.PREM_RIDER_CD) Then
                            .Append("PREM_RIDER_CD")
                            shrtFlag -= VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.PREM_RIDER_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.PREM_RIDER_DESC) Then
                            .Append("PREM_RIDER_DESC")
                            shrtFlag -= VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.PREM_RIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.BENEFITS) Then
                            .Append("BENEFITS")
                            shrtFlag -= VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.BENEFITS

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As VW_POLICY_PREM_RIDER_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL = VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.None)
            With Command.Parameters
                If Not isnothing(Value.PREM_RIDER_CD) And Not CheckBit(ExcludeValue, VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.PREM_RIDER_CD) Then .AddWithValue("@prem_rider_cd", Value.PREM_RIDER_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.PREM_RIDER_DESC) And Not CheckBit(ExcludeValue, VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.PREM_RIDER_DESC) Then .AddWithValue("@prem_rider_desc", Value.PREM_RIDER_DESC)
                If Value.BENEFITS >= 0 And Not CheckBit(ExcludeValue, VW_POLICY_PREM_RIDER_DTL_VO.Enum_VW_POLICY_PREM_RIDER_DTL.BENEFITS) Then .AddWithValue("@benefits", Value.BENEFITS)
            End With
        End Sub
    End Class

#End Region

#Region "vw_poicy_fund_mstr"

    <Serializable()> _
    Public Class VW_POLICY_FUND_MSTR_VO

        Public FUND_CD As String
        Public PRDT_CD As String
        Public ALLOCATION As Double = -1
        Public FUND_DESC As String
        Public POLICY_SEQ_CD As String

        Public Enum Enum_VW_POLICY_FUND_MSTR As Short
            NONE = 0
            fund_cd = 1
            prdt_cd = 2
            allocation = 4
            fund_desc = 8
            policy_seq_cd = 16
        End Enum

    End Class

    Public Class VW_POLICY_FUND_MSTR_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_policy_fund_mstr_VO, Optional ByVal ExcludeValue As vw_policy_fund_mstr_VO.Enum_vw_policy_fund_mstr = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_policy_fund_mstr " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike) & _
                                    " Order by fund_desc"
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_FUND_MSTR_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr = VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.FUND_CD) Then shrtFlag += VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.FUND_CD
                If Not isnothing(.PRDT_CD) Then shrtFlag += VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.PRDT_CD
                If .ALLOCATION >= 0 Then shrtFlag += VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.ALLOCATION
                If Not isnothing(.FUND_DESC) Then shrtFlag += VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.FUND_DESC
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.POLICY_SEQ_CD
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_policy_fund_mstr SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_policy_fund_mstr (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_policy_fund_mstr WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.FUND_CD) Then
                            .Append("FUND_CD")
                            shrtFlag -= VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.FUND_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.PRDT_CD) Then
                            .Append("PRDT_CD")
                            shrtFlag -= VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.PRDT_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.ALLOCATION) Then
                            .Append("ALLOCATION")
                            shrtFlag -= VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.ALLOCATION

                        ElseIf CheckBit(shrtFlag, VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.FUND_DESC) Then
                            .Append("FUND_DESC")
                            shrtFlag -= VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.FUND_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_FUND_MSTR_VO.Enum_vw_policy_fund_mstr.POLICY_SEQ_CD

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            '.Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_policy_fund_mstr_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_policy_fund_mstr_VO.Enum_vw_policy_fund_mstr = vw_policy_fund_mstr_VO.Enum_vw_policy_fund_mstr.None)
            With Command.Parameters
                If Not isnothing(Value.FUND_CD) And Not CheckBit(ExcludeValue, vw_policy_fund_mstr_VO.Enum_vw_policy_fund_mstr.FUND_CD) Then .AddWithValue("@fund_cd", Value.FUND_CD)
                If Not isnothing(Value.PRDT_CD) And Not CheckBit(ExcludeValue, vw_policy_fund_mstr_VO.Enum_vw_policy_fund_mstr.PRDT_CD) Then .AddWithValue("@prdt_cd", Value.PRDT_CD)
                If Value.ALLOCATION >= 0 And Not CheckBit(ExcludeValue, vw_policy_fund_mstr_VO.Enum_vw_policy_fund_mstr.ALLOCATION) Then .AddWithValue("@allocation", Value.ALLOCATION)
                If Not isnothing(Value.FUND_DESC) And Not CheckBit(ExcludeValue, vw_policy_fund_mstr_VO.Enum_vw_policy_fund_mstr.FUND_DESC) Then .AddWithValue("@fund_desc", Value.FUND_DESC)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_fund_mstr_VO.Enum_vw_policy_fund_mstr.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As vw_policy_fund_mstr_VO, Optional ByVal ExcludeValue As vw_policy_fund_mstr_VO.Enum_vw_policy_fund_mstr = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_policy_fund_mstr " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "vw_policy_adv_dtl"

    <Serializable()> _
    Public Class VW_POLICY_ADV_DTL_VO

        Public ADVISOR_CD As String
        Public POLICY_SEQ_CD As String
        Public ADVISOR_NAME As String
        Public POLICY_ADV_START_DT As Date
        Public POLICY_ADV_END_DT As Date

        Public Enum Enum_VW_POLICY_ADV_DTL As Short
            NONE = 0
            advisor_cd = 1
            policy_seq_cd = 2
            advisor_name = 4
            policy_adv_start_dt = 8
            policy_adv_end_dt = 16
        End Enum

    End Class

    Public Class VW_POLICY_ADV_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As VW_POLICY_ADV_DTL_VO, Optional ByVal ExcludeValue As VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM VW_POLICY_ADV_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_ADV_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL = VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.ADVISOR_CD) Then shrtFlag += VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.advisor_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_seq_cd
                If Not IsNothing(.ADVISOR_NAME) Then shrtFlag += VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.advisor_name
                If Year(.POLICY_ADV_START_DT) > 1 Then shrtFlag += VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_adv_start_dt
                If Year(.POLICY_ADV_END_DT) > 1 Then shrtFlag += VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_adv_end_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE VW_POLICY_ADV_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO VW_POLICY_ADV_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM VW_POLICY_ADV_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.advisor_cd) Then
                            .Append("ADVISOR_CD")
                            shrtFlag -= VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.advisor_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.advisor_name) Then
                            .Append("ADVISOR_NAME")
                            shrtFlag -= VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.advisor_name

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_adv_start_dt) Then
                            .Append("POLICY_ADV_START_DT")
                            shrtFlag -= VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_adv_start_dt

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_adv_end_dt) Then
                            .Append("POLICY_ADV_END_DT")
                            shrtFlag -= VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_adv_end_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As VW_POLICY_ADV_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL = VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.advisor_cd) Then .AddWithValue("@advisor_cd", Value.ADVISOR_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.ADVISOR_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.advisor_name) Then .AddWithValue("@advisor_name", Value.ADVISOR_NAME)
                If Year(Value.POLICY_ADV_START_DT) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_adv_start_dt) Then .AddWithValue("@policy_adv_start_dt", Value.POLICY_ADV_START_DT)
                If Year(Value.POLICY_ADV_END_DT) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_ADV_DTL_VO.Enum_VW_POLICY_ADV_DTL.policy_adv_end_dt) Then .AddWithValue("@policy_adv_end_dt", Value.POLICY_ADV_END_DT)
            End With
        End Sub
    End Class

#End Region

#Region "vw_policy_issue_dtl"

    <Serializable()> _
    Public Class VW_POLICY_ISSUE_DTL_VO

        Public POLICY_ISSUE_CD As String
        Public POLICY_SEQ_CD As String
        Public NAME As String
        Public REMARKS As String
        Public POLICY_ISSUE_DT As Date
        Public ISSUE_TYPE As String
        Public ISSUE_STATUS As String

        Public Enum Enum_VW_POLICY_ISSUE_DTL As Short
            NONE = 0
            policy_issue_cd = 1
            policy_seq_cd = 2
            Name = 4
            remarks = 8
            policy_issue_dt = 16
            issue_type = 32
            Issue_Status = 64
        End Enum

    End Class

    Public Class VW_POLICY_ISSUE_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As VW_POLICY_ISSUE_DTL_VO, Optional ByVal ExcludeValue As VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM VW_POLICY_ISSUE_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_ISSUE_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL = VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.POLICY_ISSUE_CD) Then shrtFlag += VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_issue_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_seq_cd
                If Not IsNothing(.NAME) Then shrtFlag += VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.Name
                If Not IsNothing(.REMARKS) Then shrtFlag += VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.remarks
                If Year(.POLICY_ISSUE_DT) > 1 Then shrtFlag += VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_issue_dt
                If Not IsNothing(.ISSUE_TYPE) Then shrtFlag += VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.issue_type
                If Not IsNothing(.ISSUE_STATUS) Then shrtFlag += VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.Issue_Status
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE VW_POLICY_ISSUE_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO VW_POLICY_ISSUE_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM VW_POLICY_ISSUE_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_issue_cd) Then
                            .Append("POLICY_ISSUE_CD")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_issue_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.Name) Then
                            .Append("NAME")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.Name

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.remarks) Then
                            .Append("REMARKS")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.remarks

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_issue_dt) Then
                            .Append("POLICY_ISSUE_DT")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_issue_dt

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.issue_type) Then
                            .Append("ISSUE_TYPE")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.issue_type

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.Issue_Status) Then
                            .Append("ISSUE_STATUS")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.Issue_Status

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As VW_POLICY_ISSUE_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL = VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_ISSUE_CD) And Not CheckBit(ExcludeValue, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_issue_cd) Then .AddWithValue("@policy_issue_cd", Value.POLICY_ISSUE_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.NAME) And Not CheckBit(ExcludeValue, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.Name) Then .AddWithValue("@Name", Value.NAME)
                If Not IsNothing(Value.REMARKS) And Not CheckBit(ExcludeValue, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.remarks) Then .AddWithValue("@remarks", Value.REMARKS)
                If Year(Value.POLICY_ISSUE_DT) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.policy_issue_dt) Then .AddWithValue("@policy_issue_dt", Value.POLICY_ISSUE_DT)
                If Not IsNothing(Value.ISSUE_TYPE) And Not CheckBit(ExcludeValue, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.issue_type) Then .AddWithValue("@issue_type", Value.ISSUE_TYPE)
                If Not IsNothing(Value.ISSUE_STATUS) And Not CheckBit(ExcludeValue, VW_POLICY_ISSUE_DTL_VO.Enum_VW_POLICY_ISSUE_DTL.Issue_Status) Then .AddWithValue("@Issue_Status", Value.ISSUE_STATUS)
            End With
        End Sub
    End Class


#End Region

#Region "vw_policy_issue_dtl_search"

    <Serializable()> _
    Public Class VW_POLICY_ISSUE_DTL_SEARCH_VO

        Public POLICY_SEQ_CD As String
        Public POLICY_ISSUE_CD As String
        Public CLIENTNAME As String
        Public POLICY_NO As String
        Public POLICY_ISSUE_DT As Date
        Public POLICY_ISSUE_DT_END As Date
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public STATUS As String
        Public REMARKS As String
        Public PROCESS_ST As String
        Public ADVISOR As String
        Public REMARKS_FULL As String
        Public POLICY_CLIENT_LAST_NAME As String
        Public POLICY_CLIENT_FIRST_NAME As String

        Public Enum Enum_vw_policy_issue_dtl_search As Integer
            NONE = 0
            policy_seq_cd = 1
            policy_issue_cd = 2
            ClientName = 4
            policy_no = 8
            policy_issue_dt = 16
            policy_issue_dt_END = 32
            provider_desc = 64
            prdt_desc = 128
            Status = 256
            Remarks = 512
            process_st = 1024
            advisor = 2048
            Remarks_full = 4096
            policy_client_last_name = 8192
            policy_client_first_name = 16384
        End Enum

    End Class

    Public Class VW_POLICY_ISSUE_DTL_SEARCH_DAO
        Inherits DAOMain.CommonDAO

        Public Function Search(ByVal Value As vw_policy_issue_dtl_search_VO, Optional ByVal ExcludeValue As vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "Select distinct policy_seq_cd " & _
                                    ", policy_issue_cd " & _
                                    ", clientname " & _
                                    ", policy_no" & _
                                    ", policy_issue_dt " & _
                                    ", provider_desc " & _
                                    ", prdt_desc " & _
                                    ", status " & _
                                    ", remarks " & _
                                    ", process_st " & _
                                    ", advisor " & _
                                    ", remarks_full " & _
                            " FROM vw_policy_issue_dtl_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike) & _
                                    " Order by policy_issue_dt"
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_ISSUE_DTL_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search = VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_SEQ_CD
                If Not isnothing(.POLICY_ISSUE_CD) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_CD
                If Not isnothing(.CLIENTNAME) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.CLIENTNAME
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_NO
                If Year(.POLICY_ISSUE_DT) > 1 Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_DT
                If Year(.POLICY_ISSUE_DT_END) > 1 Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_DT_END
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.PROVIDER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.PRDT_DESC
                If Not isnothing(.STATUS) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.STATUS
                If Not isnothing(.REMARKS) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.REMARKS
                If Not isnothing(.PROCESS_ST) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.PROCESS_ST
                If Not isnothing(.ADVISOR) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.ADVISOR
                If Not isnothing(.REMARKS_FULL) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.REMARKS_FULL
                If Not isnothing(.POLICY_CLIENT_LAST_NAME) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_CLIENT_LAST_NAME
                If Not isnothing(.POLICY_CLIENT_FIRST_NAME) Then shrtFlag += VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_CLIENT_FIRST_NAME
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_policy_issue_dtl_search SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_policy_issue_dtl_search (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_policy_issue_dtl_search WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_CD) Then
                            .Append("POLICY_ISSUE_CD")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.CLIENTNAME) Then
                            .Append("CLIENTNAME")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.CLIENTNAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_DT) Then
                            If CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_DT_END) Then
                                shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_DT
                                shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_DT_END
                                .Append(" POLICY_ISSUE_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.STATUS) Then
                            .Append("STATUS")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.STATUS

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.REMARKS) Then
                            .Append("REMARKS")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.REMARKS

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.PROCESS_ST) Then
                            .Append("PROCESS_ST")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.PROCESS_ST

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.ADVISOR) Then
                            .Append("ADVISOR")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.ADVISOR

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.REMARKS_FULL) Then
                            .Append("REMARKS_FULL")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.REMARKS_FULL

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_CLIENT_LAST_NAME) Then
                            .Append("POLICY_CLIENT_LAST_NAME")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_CLIENT_LAST_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_CLIENT_FIRST_NAME) Then
                            .Append("POLICY_CLIENT_FIRST_NAME")
                            shrtFlag -= VW_POLICY_ISSUE_DTL_SEARCH_VO.Enum_vw_policy_issue_dtl_search.POLICY_CLIENT_FIRST_NAME

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            '.Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_policy_issue_dtl_search_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search = vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.POLICY_ISSUE_CD) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_CD) Then .AddWithValue("@policy_issue_cd", Value.POLICY_ISSUE_CD)
                If Not isnothing(Value.CLIENTNAME) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.CLIENTNAME) Then .AddWithValue("@ClientName", Value.CLIENTNAME)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Year(Value.POLICY_ISSUE_DT) > 1 And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_DT) Then .AddWithValue("@policy_issue_dt", Value.POLICY_ISSUE_DT)
                If Year(Value.POLICY_ISSUE_DT_END) > 1 And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.POLICY_ISSUE_DT_END) Then .AddWithValue("@policy_issue_dt_END", Value.POLICY_ISSUE_DT_END)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Not isnothing(Value.STATUS) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.STATUS) Then .AddWithValue("@Status", Value.STATUS)
                If Not isnothing(Value.REMARKS) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.REMARKS) Then .AddWithValue("@Remarks", Value.REMARKS)
                If Not isnothing(Value.PROCESS_ST) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.PROCESS_ST) Then .AddWithValue("@process_st", Value.PROCESS_ST)
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.ADVISOR) Then .AddWithValue("@advisor", Value.ADVISOR)
                If Not isnothing(Value.REMARKS_FULL) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.REMARKS_FULL) Then .AddWithValue("@Remarks_full", Value.REMARKS_FULL)
                If Not isnothing(Value.POLICY_CLIENT_LAST_NAME) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.POLICY_CLIENT_LAST_NAME) Then .AddWithValue("@policy_client_last_name", Value.POLICY_CLIENT_LAST_NAME)
                If Not isnothing(Value.POLICY_CLIENT_FIRST_NAME) And Not CheckBit(ExcludeValue, vw_policy_issue_dtl_search_VO.Enum_vw_policy_issue_dtl_search.POLICY_CLIENT_FIRST_NAME) Then .AddWithValue("@policy_client_first_name", Value.POLICY_CLIENT_FIRST_NAME)
            End With
        End Sub

    End Class

#End Region

#Region "vw_policy_ref_dtl"

    <Serializable()> _
    Public Class VW_POLICY_REF_DTL_VO

        Public POLICY_SEQ_NO As String
        Public REFERRAL_CD As String
        Public REF_NAME As String
        Public REMARKS As String
        Public STATUS As String

        Public Enum Enum_VW_POLICY_REF_DTL As Short
            NONE = 0
            policy_seq_no = 1
            referral_cd = 2
            ref_name = 4
            remarks = 8
            Status = 16
        End Enum

    End Class

    Public Class VW_POLICY_REF_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As VW_POLICY_REF_DTL_VO, Optional ByVal ExcludeValue As VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM VW_POLICY_REF_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_REF_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL = VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.POLICY_SEQ_NO) Then shrtFlag += VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.POLICY_SEQ_NO
                If Not isnothing(.REFERRAL_CD) Then shrtFlag += VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REFERRAL_CD
                If Not isnothing(.REF_NAME) Then shrtFlag += VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REF_NAME
                If Not isnothing(.REMARKS) Then shrtFlag += VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REMARKS
                If Not isnothing(.STATUS) Then shrtFlag += VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.STATUS
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE VW_POLICY_REF_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO VW_POLICY_REF_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM VW_POLICY_REF_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.POLICY_SEQ_NO) Then
                            .Append("POLICY_SEQ_NO")
                            shrtFlag -= VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.POLICY_SEQ_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REFERRAL_CD) Then
                            .Append("REFERRAL_CD")
                            shrtFlag -= VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REFERRAL_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REF_NAME) Then
                            .Append("REF_NAME")
                            shrtFlag -= VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REF_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REMARKS) Then
                            .Append("REMARKS")
                            shrtFlag -= VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REMARKS

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.STATUS) Then
                            .Append("STATUS")
                            shrtFlag -= VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.STATUS

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As VW_POLICY_REF_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL = VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_SEQ_NO) And Not CheckBit(ExcludeValue, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.POLICY_SEQ_NO) Then .AddWithValue("@policy_seq_no", Value.POLICY_SEQ_NO)
                If Not isnothing(Value.REFERRAL_CD) And Not CheckBit(ExcludeValue, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REFERRAL_CD) Then .AddWithValue("@referral_cd", Value.REFERRAL_CD)
                If Not isnothing(Value.REF_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REF_NAME) Then .AddWithValue("@ref_name", Value.REF_NAME)
                If Not isnothing(Value.REMARKS) And Not CheckBit(ExcludeValue, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.REMARKS) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not isnothing(Value.STATUS) And Not CheckBit(ExcludeValue, VW_POLICY_REF_DTL_VO.Enum_VW_POLICY_REF_DTL.STATUS) Then .AddWithValue("@Status", Value.STATUS)
            End With
        End Sub
    End Class


#End Region

#Region "vw_policy_ref_dtl_search"

    <Serializable()> _
    Public Class VW_POLICY_REF_DTL_SEARCH_VO

        Public REFERRAL_CD As String
        Public POLICY_SEQ_NO As String
        Public POLICY_NO As String
        Public CLIENT_NAME As String
        Public REFERRAL_NAME As String
        Public ADVISOR_NAME As String
        Public REMARKS As String
        Public STATUS As String
        Public ADVISOR As String

        Public Enum Enum_VW_POLICY_REF_DTL_SEARCH As Short
            NONE = 0
            referral_cd = 1
            policy_seq_no = 2
            policy_no = 4
            Client_Name = 8
            Referral_Name = 16
            advisor_name = 32
            remarks = 64
            Status = 128
            advisor = 256
        End Enum

    End Class

    Public Class VW_POLICY_REF_DTL_SEARCH_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_policy_ref_dtl_search_VO, Optional ByVal ExcludeValue As vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_policy_ref_dtl_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_REF_DTL_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search = VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.REFERRAL_CD) Then shrtFlag += VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_CD
                If Not isnothing(.POLICY_SEQ_NO) Then shrtFlag += VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.POLICY_SEQ_NO
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.POLICY_NO
                If Not isnothing(.CLIENT_NAME) Then shrtFlag += VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.CLIENT_NAME
                If Not isnothing(.REFERRAL_NAME) Then shrtFlag += VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_NAME
                If Not isnothing(.ADVISOR_NAME) Then shrtFlag += VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.ADVISOR_NAME
                If Not isnothing(.REMARKS) Then shrtFlag += VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.REMARKS
                If Not isnothing(.STATUS) Then shrtFlag += VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.STATUS
                If Not isnothing(.ADVISOR) Then shrtFlag += VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.ADVISOR
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_policy_ref_dtl_search SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_policy_ref_dtl_search (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_policy_ref_dtl_search WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_CD) Then
                            .Append("REFERRAL_CD")
                            shrtFlag -= VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.POLICY_SEQ_NO) Then
                            .Append("POLICY_SEQ_NO")
                            shrtFlag -= VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.POLICY_SEQ_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.CLIENT_NAME) Then
                            .Append("CLIENT_NAME")
                            shrtFlag -= VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.CLIENT_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_NAME) Then
                            .Append("REFERRAL_NAME")
                            shrtFlag -= VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.ADVISOR_NAME) Then
                            .Append("ADVISOR_NAME")
                            shrtFlag -= VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.ADVISOR_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.REMARKS) Then
                            .Append("REMARKS")
                            shrtFlag -= VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.REMARKS

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.STATUS) Then
                            .Append("STATUS")
                            shrtFlag -= VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.STATUS

                        ElseIf CheckBit(shrtFlag, VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.ADVISOR) Then
                            .Append("ADVISOR")
                            shrtFlag -= VW_POLICY_REF_DTL_SEARCH_VO.Enum_vw_policy_ref_dtl_search.ADVISOR

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_policy_ref_dtl_search_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search = vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.None)
            With Command.Parameters
                If Not isnothing(Value.REFERRAL_CD) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_CD) Then .AddWithValue("@referral_cd", Value.REFERRAL_CD)
                If Not isnothing(Value.POLICY_SEQ_NO) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.POLICY_SEQ_NO) Then .AddWithValue("@policy_seq_no", Value.POLICY_SEQ_NO)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.CLIENT_NAME) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.CLIENT_NAME) Then .AddWithValue("@Client_Name", Value.CLIENT_NAME)
                If Not isnothing(Value.REFERRAL_NAME) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_NAME) Then .AddWithValue("@Referral_Name", Value.REFERRAL_NAME)
                If Not isnothing(Value.ADVISOR_NAME) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.ADVISOR_NAME) Then .AddWithValue("@advisor_name", Value.ADVISOR_NAME)
                If Not isnothing(Value.REMARKS) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.REMARKS) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not isnothing(Value.STATUS) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.STATUS) Then .AddWithValue("@Status", Value.STATUS)
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.ADVISOR) Then .AddWithValue("@advisor", Value.ADVISOR)
            End With
        End Sub
        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As vw_policy_ref_dtl_search_VO, Optional ByVal ExcludeValue As vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search = vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.None)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not isnothing(Value.REFERRAL_CD) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_CD) Then .Add("@referral_cd", Value.REFERRAL_CD)
                If Not isnothing(Value.POLICY_SEQ_NO) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.POLICY_SEQ_NO) Then .Add("@policy_seq_no", Value.POLICY_SEQ_NO)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.POLICY_NO) Then .Add("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.CLIENT_NAME) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.CLIENT_NAME) Then .Add("@Client_Name", Value.CLIENT_NAME)
                If Not isnothing(Value.REFERRAL_NAME) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.REFERRAL_NAME) Then .Add("@Referral_Name", Value.REFERRAL_NAME)
                If Not isnothing(Value.ADVISOR_NAME) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.ADVISOR_NAME) Then .Add("@advisor_name", Value.ADVISOR_NAME)
                If Not isnothing(Value.REMARKS) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.REMARKS) Then .Add("@remarks", Value.REMARKS)
                If Not isnothing(Value.STATUS) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.STATUS) Then .Add("@Status", Value.STATUS)
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search.ADVISOR) Then .Add("@advisor", Value.ADVISOR)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As vw_policy_ref_dtl_search_VO, Optional ByVal ExcludeValue As vw_policy_ref_dtl_search_VO.Enum_vw_policy_ref_dtl_search = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_policy_ref_dtl_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "vw_policy_premium_dtl"

    <Serializable()> _
    Public Class VW_POLICY_PREMIUM_DTL_VO

        Public POLICY_SEQ_CD As String
        Public POLICY_PREMIUM_CD As String
        Public PAYMENT_SEQ_CD As String
        Public CLIENT_NAME As String
        Public PAYMENT_NO As String
        Public POLICY_NO As String
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public POLICY_DUE_DT As Date
        Public POLICY_DUE_DT_END As Date
        Public PAY_TAG As Integer = -1
        Public PROVIDER_CD As String
        Public PRDT_CD As String
        Public PAYMENT_DT As Date
        Public PAYMENT_DT_END As Date
        Public AR_DATE As Date
        Public AR_DATE_END As Date
        Public PAYMENT_AMT As Double = -1
        Public REMARKS As String
        Public DISPATCH_NO As String
        Public CONFIRM_NO As String
        Public PAYMENT_FORM As String
        Public PAYMENT_FORM_DESC As String
        Public CURRENCY_CD As String
        Public CONTRIBUTION_AMT As Double = -1
        Public ADVISOR_CD As String
        Public YEAR_DUE As Integer = -1
        Public POLICY_CLIENT_LAST_NAME As String
        Public POLICY_CLIENT_FIRST_NAME As String

        Public Enum Enum_vw_policy_premium_dtl As Integer
            NONE = 0
            policy_seq_cd = 1
            policy_premium_cd = 2
            payment_seq_cd = 4
            Client_Name = 8
            payment_no = 16
            policy_no = 32
            provider_desc = 64
            prdt_desc = 128
            policy_due_dt = 256
            policy_due_dt_END = 512
            pay_tag = 1024
            provider_cd = 2048
            prdt_cd = 4096
            payment_dt = 8192
            payment_dt_END = 16384
            ar_date = 32768
            ar_date_END = 65536
            payment_amt = 131072
            remarks = 262144
            dispatch_no = 524288
            confirm_no = 1048576
            payment_form = 2097152
            Payment_form_desc = 4194304
            currency_cd = 8388608
            contribution_amt = 16777216
            Advisor_Cd = 33554432
            year_due = 67108864
            policy_client_last_name = 134217728
            policy_client_first_name = 268435456
        End Enum

    End Class

    Public Class VW_POLICY_PREMIUM_DTL_DAO
        Inherits DAOMain.CommonDAO

        Public Function Search(ByVal Value As vw_policy_premium_dtl_VO, Optional ByVal ExcludeValue As vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "Select Distinct " & _
                                    " policy_seq_cd, " & _
                                    " policy_premium_cd, " & _
                                    " payment_seq_cd, " & _
                                    " client_name, " & _
                                    " payment_no, " & _
                                    " policy_no, " & _
                                    " provider_desc, " & _
                                    " prdt_desc, " & _
                                    " policy_due_dt, " & _
                                    " pay_tag, " & _
                                    " provider_cd, " & _
                                    " prdt_cd, " & _
                                    " payment_dt, " & _
                                    " ar_date, " & _
                                    " payment_amt, " & _
                                    " remarks, " & _
                                    " dispatch_no, " & _
                                    " confirm_no, " & _
                                    " payment_form, " & _
                                    " payment_form_desc, " & _
                                    " currency_cd, " & _
                                    " contribution_amt, " & _
                                    " advisor_cd, " & _
                                    " year_due " & _
                                " From vw_policy_premium_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike) & " Order by policy_due_dt"
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_PREMIUM_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl = VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_SEQ_CD
                If Not isnothing(.POLICY_PREMIUM_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_PREMIUM_CD
                If Not isnothing(.PAYMENT_SEQ_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_SEQ_CD
                If Not isnothing(.CLIENT_NAME) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CLIENT_NAME
                If Not isnothing(.PAYMENT_NO) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_NO
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_NO
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PROVIDER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PRDT_DESC
                If Year(.POLICY_DUE_DT) > 1 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_DUE_DT
                If Year(.POLICY_DUE_DT_END) > 1 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_DUE_DT_END
                If .PAY_TAG >= 0 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAY_TAG
                If Not isnothing(.PROVIDER_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PROVIDER_CD
                If Not isnothing(.PRDT_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PRDT_CD
                If Year(.PAYMENT_DT) > 1 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_DT
                If Year(.PAYMENT_DT_END) > 1 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_DT_END
                If Year(.AR_DATE) > 1 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.AR_DATE
                If Year(.AR_DATE_END) > 1 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.AR_DATE_END
                If .PAYMENT_AMT >= 0 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_AMT
                If Not isnothing(.REMARKS) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.REMARKS
                If Not isnothing(.DISPATCH_NO) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.DISPATCH_NO
                If Not isnothing(.CONFIRM_NO) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CONFIRM_NO
                If Not isnothing(.PAYMENT_FORM) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_FORM
                If Not isnothing(.PAYMENT_FORM_DESC) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_FORM_DESC
                If Not isnothing(.CURRENCY_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CURRENCY_CD
                If .CONTRIBUTION_AMT >= 0 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CONTRIBUTION_AMT
                If Not isnothing(.ADVISOR_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.ADVISOR_CD
                If .YEAR_DUE >= 0 Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.YEAR_DUE
                If Not isnothing(.POLICY_CLIENT_LAST_NAME) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_CLIENT_LAST_NAME
                If Not isnothing(.POLICY_CLIENT_FIRST_NAME) Then shrtFlag += VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_CLIENT_FIRST_NAME
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_policy_premium_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_policy_premium_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_policy_premium_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_PREMIUM_CD) Then
                            .Append("POLICY_PREMIUM_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_PREMIUM_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_SEQ_CD) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CLIENT_NAME) Then
                            .Append("CLIENT_NAME")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CLIENT_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_NO) Then
                            .Append("PAYMENT_NO")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_DUE_DT) Then
                            If CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_DUE_DT_END) Then
                                shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_DUE_DT
                                shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_DUE_DT_END
                                .Append(" POLICY_DUE_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAY_TAG) Then
                            .Append("PAY_TAG")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAY_TAG

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PROVIDER_CD) Then
                            .Append("PROVIDER_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PROVIDER_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PRDT_CD) Then
                            .Append("PRDT_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PRDT_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_DT) Then
                            If CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_DT_END) Then
                                shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_DT
                                shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_DT_END
                                .Append(" PAYMENT_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.AR_DATE) Then
                            If CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.AR_DATE_END) Then
                                shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.AR_DATE
                                shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.AR_DATE_END
                                .Append(" AR_DATE between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_AMT) Then
                            .Append("PAYMENT_AMT")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_AMT

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.REMARKS) Then
                            .Append("REMARKS")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.REMARKS

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.DISPATCH_NO) Then
                            .Append("DISPATCH_NO")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.DISPATCH_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CONFIRM_NO) Then
                            .Append("CONFIRM_NO")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CONFIRM_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_FORM) Then
                            .Append("PAYMENT_FORM")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_FORM

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_FORM_DESC) Then
                            .Append("PAYMENT_FORM_DESC")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.PAYMENT_FORM_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CURRENCY_CD) Then
                            .Append("CURRENCY_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CURRENCY_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CONTRIBUTION_AMT) Then
                            .Append("CONTRIBUTION_AMT")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.CONTRIBUTION_AMT

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.ADVISOR_CD) Then
                            .Append("ADVISOR_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.ADVISOR_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.YEAR_DUE) Then
                            .Append("YEAR_DUE")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.YEAR_DUE

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_CLIENT_LAST_NAME) Then
                            .Append("POLICY_CLIENT_LAST_NAME")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_CLIENT_LAST_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_CLIENT_FIRST_NAME) Then
                            .Append("POLICY_CLIENT_FIRST_NAME")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_VO.Enum_vw_policy_premium_dtl.POLICY_CLIENT_FIRST_NAME

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_policy_premium_dtl_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl = vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.POLICY_PREMIUM_CD) Then .AddWithValue("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Not isnothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PAYMENT_SEQ_CD) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not isnothing(Value.CLIENT_NAME) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.CLIENT_NAME) Then .AddWithValue("@Client_Name", Value.CLIENT_NAME)
                If Not isnothing(Value.PAYMENT_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PAYMENT_NO) Then .AddWithValue("@payment_no", Value.PAYMENT_NO)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Year(Value.POLICY_DUE_DT) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.POLICY_DUE_DT) Then .AddWithValue("@policy_due_dt", Value.POLICY_DUE_DT)
                If Year(Value.POLICY_DUE_DT_END) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.POLICY_DUE_DT_END) Then .AddWithValue("@policy_due_dt_END", Value.POLICY_DUE_DT_END)
                If Value.PAY_TAG >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PAY_TAG) Then .AddWithValue("@pay_tag", Value.PAY_TAG)
                If Not isnothing(Value.PROVIDER_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PROVIDER_CD) Then .AddWithValue("@provider_cd", Value.PROVIDER_CD)
                If Not isnothing(Value.PRDT_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PRDT_CD) Then .AddWithValue("@prdt_cd", Value.PRDT_CD)
                If Year(Value.PAYMENT_DT) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PAYMENT_DT) Then .AddWithValue("@payment_dt", Value.PAYMENT_DT)
                If Year(Value.PAYMENT_DT_END) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PAYMENT_DT_END) Then .AddWithValue("@payment_dt_END", Value.PAYMENT_DT_END)
                If Year(Value.AR_DATE) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.AR_DATE) Then .AddWithValue("@ar_date", Value.AR_DATE)
                If Year(Value.AR_DATE_END) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.AR_DATE_END) Then .AddWithValue("@ar_date_END", Value.AR_DATE_END)
                If Value.PAYMENT_AMT >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PAYMENT_AMT) Then .AddWithValue("@payment_amt", Value.PAYMENT_AMT)
                If Not isnothing(Value.REMARKS) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.REMARKS) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not isnothing(Value.DISPATCH_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.DISPATCH_NO) Then .AddWithValue("@dispatch_no", Value.DISPATCH_NO)
                If Not isnothing(Value.CONFIRM_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.CONFIRM_NO) Then .AddWithValue("@confirm_no", Value.CONFIRM_NO)
                If Not isnothing(Value.PAYMENT_FORM) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PAYMENT_FORM) Then .AddWithValue("@payment_form", Value.PAYMENT_FORM)
                If Not isnothing(Value.PAYMENT_FORM_DESC) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.PAYMENT_FORM_DESC) Then .AddWithValue("@Payment_form_desc", Value.PAYMENT_FORM_DESC)
                If Not isnothing(Value.CURRENCY_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.CURRENCY_CD) Then .AddWithValue("@currency_cd", Value.CURRENCY_CD)
                If Value.CONTRIBUTION_AMT >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.CONTRIBUTION_AMT) Then .AddWithValue("@contribution_amt", Value.CONTRIBUTION_AMT)
                If Not isnothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.ADVISOR_CD) Then .AddWithValue("@Advisor_Cd", Value.ADVISOR_CD)
                If Value.YEAR_DUE >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.YEAR_DUE) Then .AddWithValue("@year_due", Value.YEAR_DUE)
                If Not isnothing(Value.POLICY_CLIENT_LAST_NAME) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.POLICY_CLIENT_LAST_NAME) Then .AddWithValue("@policy_client_last_name", Value.POLICY_CLIENT_LAST_NAME)
                If Not isnothing(Value.POLICY_CLIENT_FIRST_NAME) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_VO.Enum_vw_policy_premium_dtl.POLICY_CLIENT_FIRST_NAME) Then .AddWithValue("@policy_client_first_name", Value.POLICY_CLIENT_FIRST_NAME)
            End With
        End Sub

    End Class

#End Region

#Region "vw_policy_dispatch_search"

    <Serializable()> _
    Public Class VW_POLICY_DISPATCH_SEARCH_VO

        Public POLICY_DISPATCH_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_PREMIUM_CD As String
        Public PAYMENT_SEQ_CD As String
        Public CLIENTNAME As String
        Public POLICY_NO As String
        Public PAYMENT_NO As String
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public PAYMENT_DT As Date
        Public PAYMENT_DT_END As Date
        Public DISPATCH_NO As String
        Public CONFIRM_NO As String
        Public POLICY_DISPATCH_ATTACHMENT As String
        Public POLICY_DISPATCH_DATE As Date
        Public POLICY_DISPATCH_DATE_END As Date
        Public CONTRIBUTION_DUE_DT As Date
        Public CONTRIBUTION_DUE_DT_END As Date
        Public PAYMENT_AMT As Double = -1
        Public CURRENCY As String
        Public REMARKS As String
        Public POLICY_CLIENT_LAST_NAME As String
        Public POLICY_CLIENT_FIRST_NAME As String

        Public Enum Enum_vw_policy_dispatch_search As Integer
            NONE = 0
            policy_dispatch_cd = 1
            policy_seq_cd = 2
            policy_premium_cd = 4
            payment_seq_cd = 8
            ClientName = 16
            policy_no = 32
            payment_no = 64
            provider_desc = 128
            prdt_desc = 256
            payment_dt = 512
            payment_dt_END = 1024
            dispatch_no = 2048
            confirm_no = 4096
            policy_dispatch_attachment = 8192
            policy_dispatch_date = 16384
            policy_dispatch_date_END = 32768
            contribution_due_dt = 65536
            contribution_due_dt_END = 131072
            payment_amt = 262144
            currency = 524288
            remarks = 1048576
            policy_client_last_name = 2097152
            policy_client_first_name = 4194304
        End Enum

    End Class

    Public Class VW_POLICY_DISPATCH_SEARCH_DAO
        Inherits DAOMain.CommonDAO

        Public Function Search(ByVal Value As vw_policy_dispatch_search_VO, Optional ByVal ExcludeValue As vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "Select Distinct  " & _
                         " policy_dispatch_cd, " & _
                         " policy_seq_cd, " & _
                         " policy_premium_cd, " & _
                         " payment_seq_cd, " & _
                         " clientname, " & _
                         " policy_no, " & _
                         " payment_no, " & _
                         " provider_desc, " & _
                         " prdt_desc, " & _
                         " payment_dt, " & _
                         " dispatch_no, " & _
                         " confirm_no, " & _
                         " policy_dispatch_attachment, " & _
                         " policy_dispatch_date, " & _
                         " contribution_due_dt, " & _
                         " payment_amt, " & _
                         " currency, " & _
                         " remarks " & _
                        " From vw_policy_dispatch_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike) & " Order by payment_dt"
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_DISPATCH_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search = VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not isnothing(.POLICY_DISPATCH_CD) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_SEQ_CD
                If Not isnothing(.POLICY_PREMIUM_CD) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_PREMIUM_CD
                If Not isnothing(.PAYMENT_SEQ_CD) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_SEQ_CD
                If Not isnothing(.CLIENTNAME) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CLIENTNAME
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_NO
                If Not isnothing(.PAYMENT_NO) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_NO
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PROVIDER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PRDT_DESC
                If Year(.PAYMENT_DT) > 1 Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_DT
                If Year(.PAYMENT_DT_END) > 1 Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_DT_END
                If Not isnothing(.DISPATCH_NO) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.DISPATCH_NO
                If Not isnothing(.CONFIRM_NO) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CONFIRM_NO
                If Not isnothing(.POLICY_DISPATCH_ATTACHMENT) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_ATTACHMENT
                If Year(.POLICY_DISPATCH_DATE) > 1 Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_DATE
                If Year(.POLICY_DISPATCH_DATE_END) > 1 Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_DATE_END
                If Year(.CONTRIBUTION_DUE_DT) > 1 Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CONTRIBUTION_DUE_DT
                If Year(.CONTRIBUTION_DUE_DT_END) > 1 Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CONTRIBUTION_DUE_DT_END
                If .PAYMENT_AMT >= 0 Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_AMT
                If Not isnothing(.CURRENCY) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CURRENCY
                If Not isnothing(.REMARKS) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.REMARKS
                If Not isnothing(.POLICY_CLIENT_LAST_NAME) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_CLIENT_LAST_NAME
                If Not isnothing(.POLICY_CLIENT_FIRST_NAME) Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_CLIENT_FIRST_NAME
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_policy_dispatch_search SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_policy_dispatch_search (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_policy_dispatch_search WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_CD) Then
                            .Append("POLICY_DISPATCH_CD")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_PREMIUM_CD) Then
                            .Append("POLICY_PREMIUM_CD")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_PREMIUM_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_SEQ_CD) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CLIENTNAME) Then
                            .Append("CLIENTNAME")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CLIENTNAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_NO) Then
                            .Append("PAYMENT_NO")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_DT) Then
                            If CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_DT_END) Then
                                shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_DT
                                shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_DT_END
                                .Append(" PAYMENT_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.DISPATCH_NO) Then
                            .Append("DISPATCH_NO")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.DISPATCH_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CONFIRM_NO) Then
                            .Append("CONFIRM_NO")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CONFIRM_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_ATTACHMENT) Then
                            .Append("POLICY_DISPATCH_ATTACHMENT")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_ATTACHMENT

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_DATE) Then
                            If CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_DATE_END) Then
                                shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_DATE
                                shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_DATE_END
                                .Append(" POLICY_DISPATCH_DATE between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CONTRIBUTION_DUE_DT) Then
                            If CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CONTRIBUTION_DUE_DT_END) Then
                                shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CONTRIBUTION_DUE_DT
                                shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CONTRIBUTION_DUE_DT_END
                                .Append(" CONTRIBUTION_DUE_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_AMT) Then
                            .Append("PAYMENT_AMT")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.PAYMENT_AMT

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CURRENCY) Then
                            .Append("CURRENCY")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.CURRENCY

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.REMARKS) Then
                            .Append("REMARKS")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.REMARKS

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_CLIENT_LAST_NAME) Then
                            .Append("POLICY_CLIENT_LAST_NAME")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_CLIENT_LAST_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_CLIENT_FIRST_NAME) Then
                            .Append("POLICY_CLIENT_FIRST_NAME")
                            shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_vw_policy_dispatch_search.POLICY_CLIENT_FIRST_NAME

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_policy_dispatch_search_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search = vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_DISPATCH_CD) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_CD) Then .AddWithValue("@policy_dispatch_cd", Value.POLICY_DISPATCH_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.POLICY_PREMIUM_CD) Then .AddWithValue("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Not isnothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.PAYMENT_SEQ_CD) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not isnothing(Value.CLIENTNAME) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.CLIENTNAME) Then .AddWithValue("@ClientName", Value.CLIENTNAME)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.PAYMENT_NO) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.PAYMENT_NO) Then .AddWithValue("@payment_no", Value.PAYMENT_NO)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Year(Value.PAYMENT_DT) > 1 And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.PAYMENT_DT) Then .AddWithValue("@payment_dt", Value.PAYMENT_DT)
                If Year(Value.PAYMENT_DT_END) > 1 And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.PAYMENT_DT_END) Then .AddWithValue("@payment_dt_END", Value.PAYMENT_DT_END)
                If Not isnothing(Value.DISPATCH_NO) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.DISPATCH_NO) Then .AddWithValue("@dispatch_no", Value.DISPATCH_NO)
                If Not isnothing(Value.CONFIRM_NO) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.CONFIRM_NO) Then .AddWithValue("@confirm_no", Value.CONFIRM_NO)
                If Not isnothing(Value.POLICY_DISPATCH_ATTACHMENT) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_ATTACHMENT) Then .AddWithValue("@policy_dispatch_attachment", Value.POLICY_DISPATCH_ATTACHMENT)
                If Year(Value.POLICY_DISPATCH_DATE) > 1 And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_DATE) Then .AddWithValue("@policy_dispatch_date", Value.POLICY_DISPATCH_DATE)
                If Year(Value.POLICY_DISPATCH_DATE_END) > 1 And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.POLICY_DISPATCH_DATE_END) Then .AddWithValue("@policy_dispatch_date_END", Value.POLICY_DISPATCH_DATE_END)
                If Year(Value.CONTRIBUTION_DUE_DT) > 1 And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.CONTRIBUTION_DUE_DT) Then .AddWithValue("@contribution_due_dt", Value.CONTRIBUTION_DUE_DT)
                If Year(Value.CONTRIBUTION_DUE_DT_END) > 1 And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.CONTRIBUTION_DUE_DT_END) Then .AddWithValue("@contribution_due_dt_END", Value.CONTRIBUTION_DUE_DT_END)
                If Value.PAYMENT_AMT >= 0 And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.PAYMENT_AMT) Then .AddWithValue("@payment_amt", Value.PAYMENT_AMT)
                If Not isnothing(Value.CURRENCY) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.CURRENCY) Then .AddWithValue("@currency", Value.CURRENCY)
                If Not isnothing(Value.REMARKS) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.REMARKS) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not isnothing(Value.POLICY_CLIENT_LAST_NAME) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.POLICY_CLIENT_LAST_NAME) Then .AddWithValue("@policy_client_last_name", Value.POLICY_CLIENT_LAST_NAME)
                If Not isnothing(Value.POLICY_CLIENT_FIRST_NAME) And Not CheckBit(ExcludeValue, vw_policy_dispatch_search_VO.Enum_vw_policy_dispatch_search.POLICY_CLIENT_FIRST_NAME) Then .AddWithValue("@policy_client_first_name", Value.POLICY_CLIENT_FIRST_NAME)
            End With
        End Sub

    End Class

    'If Year(.PAYMENT_DT_TO) > 1 Then shrtFlag += VW_POLICY_DISPATCH_SEARCH_VO.Enum_VW_POLICY_DISPATCH_SEARCH.payment_dt_to

    '                            If CheckBit(shrtFlag, VW_POLICY_DISPATCH_SEARCH_VO.Enum_VW_POLICY_DISPATCH_SEARCH.payment_dt_to) And QueryType = 0 Then
    '                                .Append("PAYMENT_DT BETWEEN ? AND ? ")
    '                                shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_VW_POLICY_DISPATCH_SEARCH.payment_dt_to
    '                                shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_VW_POLICY_DISPATCH_SEARCH.payment_dt
    '                                QueryType = 4
    '                            Else
    '                                .Append("PAYMENT_DT")
    '                                shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_VW_POLICY_DISPATCH_SEARCH.payment_dt
    '                            End If

    'If Year(Value.PAYMENT_DT_TO) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_DISPATCH_SEARCH_VO.Enum_VW_POLICY_DISPATCH_SEARCH.payment_dt_to) Then .AddWithValue("@payment_dt_to", Value.PAYMENT_DT_TO)
#End Region

#Region "vw_policy_confirm_search"

    <Serializable()> _
    Public Class VW_POLICY_CONFIRM_SEARCH_VO

        Public POLICY_CONFIRM_CD As String
        Public POLICY_CONFIRM_DT As Date
        Public POLICY_CONFIRM_DT_END As Date
        Public POLICY_DISPATCH_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_PREMIUM_CD As String
        Public PAYMENT_SEQ_CD As String
        Public CLIENTNAME As String
        Public POLICY_NO As String
        Public PAYMENT_NO As String
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public PAYMENT_DT As Date
        Public PAYMENT_DT_END As Date
        Public DISPATCH_NO As String
        Public CONFIRM_NO As String
        Public POLICY_DISPATCH_ATTACHMENT As String
        Public POLICY_DISPATCH_DATE As Date
        Public POLICY_DISPATCH_DATE_END As Date
        Public CONTRIBUTION_DUE_DT As Date
        Public CONTRIBUTION_DUE_DT_END As Date
        Public PAYMENT_AMT As Double = -1
        Public CURRENCY As String
        Public REMARKS As String
        Public POLICY_CLIENT_LAST_NAME As String
        Public POLICY_CLIENT_FIRST_NAME As String
        Public CONFIRM_STATUS As String

        Public Enum Enum_vw_policy_confirm_search As Integer
            NONE = 0
            policy_confirm_cd = 1
            policy_confirm_dt = 2
            policy_confirm_dt_END = 4
            policy_dispatch_cd = 8
            policy_seq_cd = 16
            policy_premium_cd = 32
            payment_seq_cd = 64
            ClientName = 128
            policy_no = 256
            payment_no = 512
            provider_desc = 1024
            prdt_desc = 2048
            payment_dt = 4096
            payment_dt_END = 8192
            dispatch_no = 16384
            confirm_no = 32768
            policy_dispatch_attachment = 65536
            policy_dispatch_date = 131072
            policy_dispatch_date_END = 262144
            contribution_due_dt = 524288
            contribution_due_dt_END = 1048576
            payment_amt = 2097152
            currency = 4194304
            remarks = 8388608
            policy_client_last_name = 16777216
            policy_client_first_name = 33554432
            confirm_status = 67108864
        End Enum

    End Class

    Public Class VW_POLICY_CONFIRM_SEARCH_DAO
        Inherits DAOMain.CommonDAO

        Public Function Search(ByVal Value As VW_POLICY_CONFIRM_SEARCH_VO, Optional ByVal ExcludeValue As VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "Select Distinct " & _
                                 " policy_confirm_cd, " & _
                                 " policy_confirm_dt, " & _
                                 " policy_dispatch_cd, " & _
                                 " policy_seq_cd, " & _
                                 " policy_premium_cd, " & _
                                 " payment_seq_cd, " & _
                                 " clientname, " & _
                                 " policy_no, " & _
                                 " payment_no, " & _
                                 " provider_desc, " & _
                                 " prdt_desc, " & _
                                 " payment_dt, " & _
                                 " dispatch_no, " & _
                                 " confirm_no, " & _
                                 " policy_dispatch_attachment, " & _
                                 " policy_dispatch_date, " & _
                                 " contribution_due_dt, " & _
                                 " payment_amt, " & _
                                 " currency, " & _
                                 " remarks " & _
                            " From vw_policy_confirm_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike) & " Order by payment_dt"
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_CONFIRM_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search = VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not IsNothing(.POLICY_CONFIRM_CD) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_cd
                If Year(.POLICY_CONFIRM_DT) > 1 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_dt
                If Year(.POLICY_CONFIRM_DT_END) > 1 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_dt_END
                If Not IsNothing(.POLICY_DISPATCH_CD) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_seq_cd
                If Not IsNothing(.POLICY_PREMIUM_CD) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_premium_cd
                If Not IsNothing(.PAYMENT_SEQ_CD) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_seq_cd
                If Not IsNothing(.CLIENTNAME) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.ClientName
                If Not IsNothing(.POLICY_NO) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_no
                If Not IsNothing(.PAYMENT_NO) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_no
                If Not IsNothing(.PROVIDER_DESC) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.provider_desc
                If Not IsNothing(.PRDT_DESC) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.prdt_desc
                If Year(.PAYMENT_DT) > 1 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt
                If Year(.PAYMENT_DT_END) > 1 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt_END
                If Not IsNothing(.DISPATCH_NO) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.dispatch_no
                If Not IsNothing(.CONFIRM_NO) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.confirm_no
                If Not IsNothing(.POLICY_DISPATCH_ATTACHMENT) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_attachment
                If Year(.POLICY_DISPATCH_DATE) > 1 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_date
                If Year(.POLICY_DISPATCH_DATE_END) > 1 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_date_END
                If Year(.CONTRIBUTION_DUE_DT) > 1 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.contribution_due_dt
                If Year(.CONTRIBUTION_DUE_DT_END) > 1 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.contribution_due_dt_END
                If .PAYMENT_AMT >= 0 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_amt
                If Not IsNothing(.CURRENCY) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.currency
                If Not IsNothing(.REMARKS) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.remarks
                If Not IsNothing(.POLICY_CLIENT_LAST_NAME) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_client_last_name
                If Not IsNothing(.POLICY_CLIENT_FIRST_NAME) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_client_first_name
                If Not IsNothing(.CONFIRM_STATUS) Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.confirm_status
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_policy_confirm_search SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_policy_confirm_search (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_policy_confirm_search WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_cd) Then
                            .Append("POLICY_CONFIRM_CD")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_dt) Then
                            If CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_dt_END) Then
                                shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_dt
                                shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_dt_END
                                .Append(" POLICY_CONFIRM_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_cd) Then
                            .Append("POLICY_DISPATCH_CD")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_premium_cd) Then
                            .Append("POLICY_PREMIUM_CD")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_premium_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_seq_cd) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_seq_cd

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.ClientName) Then
                            .Append("CLIENTNAME")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.ClientName

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_no) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_no

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_no) Then
                            .Append("PAYMENT_NO")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_no

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.provider_desc) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.provider_desc

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.prdt_desc) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.prdt_desc

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt) Then
                            If CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt_END) Then
                                shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt
                                shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt_END
                                .Append(" PAYMENT_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.dispatch_no) Then
                            .Append("DISPATCH_NO")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.dispatch_no

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.confirm_no) Then
                            .Append("CONFIRM_NO")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.confirm_no

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_attachment) Then
                            .Append("POLICY_DISPATCH_ATTACHMENT")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_attachment

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_date) Then
                            If CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_date_END) Then
                                shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_date
                                shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_date_END
                                .Append(" POLICY_DISPATCH_DATE between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.contribution_due_dt) Then
                            If CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.contribution_due_dt_END) Then
                                shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.contribution_due_dt
                                shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.contribution_due_dt_END
                                .Append(" CONTRIBUTION_DUE_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_amt) Then
                            .Append("PAYMENT_AMT")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_amt

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.currency) Then
                            .Append("CURRENCY")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.currency

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.remarks) Then
                            .Append("REMARKS")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.remarks

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_client_last_name) Then
                            .Append("POLICY_CLIENT_LAST_NAME")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_client_last_name

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_client_first_name) Then
                            .Append("POLICY_CLIENT_FIRST_NAME")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_client_first_name

                        ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.confirm_status) Then
                            .Append("CONFIRM_STATUS")
                            shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.confirm_status

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As VW_POLICY_CONFIRM_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search = VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_CONFIRM_CD) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_cd) Then .AddWithValue("@policy_confirm_cd", Value.POLICY_CONFIRM_CD)
                If Year(Value.POLICY_CONFIRM_DT) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_dt) Then .AddWithValue("@policy_confirm_dt", Value.POLICY_CONFIRM_DT)
                If Year(Value.POLICY_CONFIRM_DT_END) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_confirm_dt_END) Then .AddWithValue("@policy_confirm_dt_END", Value.POLICY_CONFIRM_DT_END)
                If Not IsNothing(Value.POLICY_DISPATCH_CD) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_cd) Then .AddWithValue("@policy_dispatch_cd", Value.POLICY_DISPATCH_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_premium_cd) Then .AddWithValue("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Not IsNothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_seq_cd) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not IsNothing(Value.CLIENTNAME) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.ClientName) Then .AddWithValue("@ClientName", Value.CLIENTNAME)
                If Not IsNothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_no) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not IsNothing(Value.PAYMENT_NO) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_no) Then .AddWithValue("@payment_no", Value.PAYMENT_NO)
                If Not IsNothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.provider_desc) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not IsNothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.prdt_desc) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Year(Value.PAYMENT_DT) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt) Then .AddWithValue("@payment_dt", Value.PAYMENT_DT)
                If Year(Value.PAYMENT_DT_END) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt_END) Then .AddWithValue("@payment_dt_END", Value.PAYMENT_DT_END)
                If Not IsNothing(Value.DISPATCH_NO) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.dispatch_no) Then .AddWithValue("@dispatch_no", Value.DISPATCH_NO)
                If Not IsNothing(Value.CONFIRM_NO) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.confirm_no) Then .AddWithValue("@confirm_no", Value.CONFIRM_NO)
                If Not IsNothing(Value.POLICY_DISPATCH_ATTACHMENT) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_attachment) Then .AddWithValue("@policy_dispatch_attachment", Value.POLICY_DISPATCH_ATTACHMENT)
                If Year(Value.POLICY_DISPATCH_DATE) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_date) Then .AddWithValue("@policy_dispatch_date", Value.POLICY_DISPATCH_DATE)
                If Year(Value.POLICY_DISPATCH_DATE_END) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_dispatch_date_END) Then .AddWithValue("@policy_dispatch_date_END", Value.POLICY_DISPATCH_DATE_END)
                If Year(Value.CONTRIBUTION_DUE_DT) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.contribution_due_dt) Then .AddWithValue("@contribution_due_dt", Value.CONTRIBUTION_DUE_DT)
                If Year(Value.CONTRIBUTION_DUE_DT_END) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.contribution_due_dt_END) Then .AddWithValue("@contribution_due_dt_END", Value.CONTRIBUTION_DUE_DT_END)
                If Value.PAYMENT_AMT >= 0 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_amt) Then .AddWithValue("@payment_amt", Value.PAYMENT_AMT)
                If Not IsNothing(Value.CURRENCY) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.currency) Then .AddWithValue("@currency", Value.CURRENCY)
                If Not IsNothing(Value.REMARKS) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.remarks) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not IsNothing(Value.POLICY_CLIENT_LAST_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_client_last_name) Then .AddWithValue("@policy_client_last_name", Value.POLICY_CLIENT_LAST_NAME)
                If Not IsNothing(Value.POLICY_CLIENT_FIRST_NAME) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.policy_client_first_name) Then .AddWithValue("@policy_client_first_name", Value.POLICY_CLIENT_FIRST_NAME)
                If Not IsNothing(Value.CONFIRM_STATUS) And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.confirm_status) Then .AddWithValue("@confirm_status", Value.CONFIRM_STATUS)
            End With
        End Sub

    End Class

    '.CommandText = "SELECT * FROM vw_policy_confirm_search " & _
    '        Replace(QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike), ";", "") & _
    '            " Order by payment_dt"

    'If Year(.PAYMENT_DT_TO) > 1 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_VW_POLICY_CONFIRM_SEARCH.payment_dt_to
    'If .STATUS >= 0 Then shrtFlag += VW_POLICY_CONFIRM_SEARCH_VO.Enum_VW_POLICY_CONFIRM_SEARCH.status

    'ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_VW_POLICY_CONFIRM_SEARCH.payment_dt) Then
    '    If CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt_to) And QueryType = 0 Then
    '        .Append("PAYMENT_DT BETWEEN ? AND ? ")
    '        shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt_to
    '        shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.payment_dt
    '        QueryType = 4
    '    Else
    '        .Append("PAYMENT_DT")
    '        shrtFlag -= VW_POLICY_DISPATCH_SEARCH_VO.Enum_VW_POLICY_DISPATCH_SEARCH.payment_dt
    '    End If

    'ElseIf CheckBit(shrtFlag, VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.status) Then
    '    Select Case Value.STATUS
    '        Case 0 'All
    '            .Append("CONFIRM_NO like '%%'")
    '        Case 1 'Confirmed
    '            .Append("CONFIRM_NO <> ''")
    '        Case 2 ' not confirmed
    '            .Append("CONFIRM_NO = ''")
    '    End Select
    '    shrtFlag -= VW_POLICY_CONFIRM_SEARCH_VO.Enum_vw_policy_confirm_search.status
    '    QueryType = 4

    'If Year(Value.PAYMENT_DT_TO) > 1 And Not CheckBit(ExcludeValue, VW_POLICY_CONFIRM_SEARCH_VO.Enum_VW_POLICY_CONFIRM_SEARCH.payment_dt_to) Then .AddWithValue("@payment_dt_to", Value.PAYMENT_DT_TO)
#End Region

#Region "vw_payment_search"
    <Serializable()> _
    Public Class VW_PAYMENT_SEARCH_VO

        Public POLICY_PREMIUM_CD As String
        Public POLICY_SEQ_CD As String
        Public NAME As String
        Public AR_NUMBER As String
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public POLICY_DUE_DT As Date
        Public CONTRIBUTION_AMT As Integer = -1
        Public LOOKUP_DESC As String
        Public PAY_TAG As Integer = -1

        Public Enum Enum_VW_PAYMENT_SEARCH As Short
            NONE = 0
            policy_premium_cd = 1
            policy_seq_cd = 2
            Name = 4
            AR_Number = 8
            provider_desc = 16
            prdt_desc = 32
            policy_due_dt = 64
            contribution_amt = 128
            Lookup_desc = 256
            pay_tag = 512
        End Enum

    End Class

    Public Class VW_PAYMENT_SEARCH_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_payment_search_VO, Optional ByVal ExcludeValue As vw_payment_search_VO.Enum_vw_payment_search = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_payment_search " & _
                        Replace(QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike), ";", "") & _
                        " order by name, policy_due_dt;"
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_PAYMENT_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search = VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.POLICY_PREMIUM_CD) Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.POLICY_PREMIUM_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.POLICY_SEQ_CD
                If Not isnothing(.NAME) Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.NAME
                If Not isnothing(.AR_NUMBER) Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.AR_NUMBER
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.PROVIDER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.PRDT_DESC
                If Year(.POLICY_DUE_DT) > 1 Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.POLICY_DUE_DT
                If .CONTRIBUTION_AMT >= 0 Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.CONTRIBUTION_AMT
                If Not isnothing(.LOOKUP_DESC) Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.LOOKUP_DESC
                If .PAY_TAG >= 0 Then shrtFlag += VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.PAY_TAG
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_payment_search SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_payment_search (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_payment_search WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.POLICY_PREMIUM_CD) Then
                            .Append("POLICY_PREMIUM_CD")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.POLICY_PREMIUM_CD

                        ElseIf CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.NAME) Then
                            .Append("NAME")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.NAME

                        ElseIf CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.AR_NUMBER) Then
                            .Append("AR_NUMBER")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.AR_NUMBER

                        ElseIf CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.POLICY_DUE_DT) Then
                            .Append("POLICY_DUE_DT")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.POLICY_DUE_DT

                        ElseIf CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.CONTRIBUTION_AMT) Then
                            .Append("CONTRIBUTION_AMT")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.CONTRIBUTION_AMT

                        ElseIf CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.LOOKUP_DESC) Then
                            .Append("LOOKUP_DESC")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.LOOKUP_DESC

                        ElseIf CheckBit(shrtFlag, VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.PAY_TAG) Then
                            .Append("PAY_TAG")
                            shrtFlag -= VW_PAYMENT_SEARCH_VO.Enum_vw_payment_search.PAY_TAG

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_payment_search_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_payment_search_VO.Enum_vw_payment_search = vw_payment_search_VO.Enum_vw_payment_search.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.POLICY_PREMIUM_CD) Then .AddWithValue("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.NAME) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.NAME) Then .AddWithValue("@Name", Value.NAME)
                If Not isnothing(Value.AR_NUMBER) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.AR_NUMBER) Then .AddWithValue("@AR_Number", Value.AR_NUMBER)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Year(Value.POLICY_DUE_DT) > 1 And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.POLICY_DUE_DT) Then .AddWithValue("@policy_due_dt", Value.POLICY_DUE_DT)
                If Value.CONTRIBUTION_AMT >= 0 And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.CONTRIBUTION_AMT) Then .AddWithValue("@contribution_amt", Value.CONTRIBUTION_AMT)
                If Not isnothing(Value.LOOKUP_DESC) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.LOOKUP_DESC) Then .AddWithValue("@Lookup_desc", Value.LOOKUP_DESC)
                If Value.PAY_TAG >= 0 And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.PAY_TAG) Then .AddWithValue("@pay_tag", Value.PAY_TAG)
            End With
        End Sub

        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As vw_payment_search_VO, Optional ByVal ExcludeValue As vw_payment_search_VO.Enum_vw_payment_search = vw_payment_search_VO.Enum_vw_payment_search.None)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not isnothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.POLICY_PREMIUM_CD) Then .Add("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.POLICY_SEQ_CD) Then .Add("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.NAME) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.NAME) Then .Add("@Name", Value.NAME)
                If Not isnothing(Value.AR_NUMBER) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.AR_NUMBER) Then .Add("@AR_Number", Value.AR_NUMBER)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.PROVIDER_DESC) Then .Add("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.PRDT_DESC) Then .Add("@prdt_desc", Value.PRDT_DESC)
                If Year(Value.POLICY_DUE_DT) > 1 And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.POLICY_DUE_DT) Then .Add("@policy_due_dt", Value.POLICY_DUE_DT)
                If Value.CONTRIBUTION_AMT >= 0 And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.CONTRIBUTION_AMT) Then .Add("@contribution_amt", Value.CONTRIBUTION_AMT)
                If Not isnothing(Value.LOOKUP_DESC) And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.LOOKUP_DESC) Then .Add("@Lookup_desc", Value.LOOKUP_DESC)
                If Value.PAY_TAG >= 0 And Not CheckBit(ExcludeValue, vw_payment_search_VO.Enum_vw_payment_search.PAY_TAG) Then .Add("@pay_tag", Value.PAY_TAG)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As vw_payment_search_VO, Optional ByVal ExcludeValue As vw_payment_search_VO.Enum_vw_payment_search = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_payment_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "vw_policy_premium_dtl_rec"

    <Serializable()> _
    Public Class VW_POLICY_PREMIUM_DTL_REC_VO

        Public POLICY_SEQ_CD As String
        Public POLICY_PREMIUM_CD As String
        Public PAYMENT_SEQ_CD As String
        Public CLIENT_NAME As String
        Public PAYMENT_NO As String
        Public POLICY_NO As String
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public POLICY_DUE_DT As Date
        Public PAY_TAG As Integer = -1
        Public PROVIDER_CD As String
        Public PRDT_CD As String
        Public AR_DATE As Date
        Public PAYMENT_DT As Date
        Public PAYMENT_AMT As Integer = -1
        Public REMARKS As String
        Public DISPATCH_NO As String
        Public CONFIRM_NO As String
        Public PAYMENT_FORM As String
        Public PAYMENT_FORM_DESC As String
        Public CURRENCY_CD As String
        Public CONTRIBUTION_AMT As Integer = -1

        Public Enum Enum_vw_policy_premium_dtl_rec As Integer
            NONE = 0
            policy_seq_cd = 1
            policy_premium_cd = 2
            payment_seq_cd = 4
            Client_Name = 8
            payment_no = 16
            policy_no = 32
            provider_desc = 64
            prdt_desc = 128
            policy_due_dt = 256
            pay_tag = 512
            provider_cd = 1024
            prdt_cd = 2048
            ar_date = 4096
            payment_dt = 8192
            payment_amt = 16384
            remarks = 32768
            dispatch_no = 65536
            confirm_no = 131072
            payment_form = 262144
            Payment_form_desc = 524288
            currency_cd = 1048576
            contribution_amt = 2097152
        End Enum

    End Class

    Public Class VW_POLICY_PREMIUM_DTL_REC_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_policy_premium_dtl_rec_VO, Optional ByVal ExcludeValue As vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_policy_premium_dtl_rec " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_POLICY_PREMIUM_DTL_REC_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec = VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_SEQ_CD
                If Not isnothing(.POLICY_PREMIUM_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_PREMIUM_CD
                If Not isnothing(.PAYMENT_SEQ_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_SEQ_CD
                If Not isnothing(.CLIENT_NAME) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CLIENT_NAME
                If Not isnothing(.PAYMENT_NO) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_NO
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_NO
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PRDT_DESC
                If Year(.POLICY_DUE_DT) > 1 Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_DUE_DT
                If .PAY_TAG >= 0 Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAY_TAG
                If Not isnothing(.PROVIDER_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_CD
                If Not isnothing(.PRDT_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PRDT_CD
                If Year(.AR_DATE) > 1 Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.AR_DATE
                If Year(.PAYMENT_DT) > 1 Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_DT
                If .PAYMENT_AMT >= 0 Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_AMT
                If Not isnothing(.REMARKS) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.REMARKS
                If Not isnothing(.DISPATCH_NO) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.DISPATCH_NO
                If Not isnothing(.CONFIRM_NO) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CONFIRM_NO
                If Not isnothing(.PAYMENT_FORM) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM
                If Not isnothing(.PAYMENT_FORM_DESC) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM_DESC
                If Not isnothing(.CURRENCY_CD) Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CURRENCY_CD
                If .CONTRIBUTION_AMT >= 0 Then shrtFlag += VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CONTRIBUTION_AMT
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_policy_premium_dtl_rec SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_policy_premium_dtl_rec (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_policy_premium_dtl_rec WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_PREMIUM_CD) Then
                            .Append("POLICY_PREMIUM_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_PREMIUM_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_SEQ_CD) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CLIENT_NAME) Then
                            .Append("CLIENT_NAME")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CLIENT_NAME

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_NO) Then
                            .Append("PAYMENT_NO")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_DUE_DT) Then
                            .Append("POLICY_DUE_DT")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.POLICY_DUE_DT

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAY_TAG) Then
                            .Append("PAY_TAG")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAY_TAG

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_CD) Then
                            .Append("PROVIDER_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PRDT_CD) Then
                            .Append("PRDT_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PRDT_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.AR_DATE) Then
                            .Append("AR_DATE")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.AR_DATE

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_DT) Then
                            .Append("PAYMENT_DT")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_DT

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_AMT) Then
                            .Append("PAYMENT_AMT")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_AMT

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.REMARKS) Then
                            .Append("REMARKS")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.REMARKS

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.DISPATCH_NO) Then
                            .Append("DISPATCH_NO")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.DISPATCH_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CONFIRM_NO) Then
                            .Append("CONFIRM_NO")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CONFIRM_NO

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM) Then
                            .Append("PAYMENT_FORM")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM_DESC) Then
                            .Append("PAYMENT_FORM_DESC")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM_DESC

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CURRENCY_CD) Then
                            .Append("CURRENCY_CD")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CURRENCY_CD

                        ElseIf CheckBit(shrtFlag, VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CONTRIBUTION_AMT) Then
                            .Append("CONTRIBUTION_AMT")
                            shrtFlag -= VW_POLICY_PREMIUM_DTL_REC_VO.Enum_vw_policy_premium_dtl_rec.CONTRIBUTION_AMT

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_policy_premium_dtl_rec_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec = vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.POLICY_PREMIUM_CD) Then .AddWithValue("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Not isnothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_SEQ_CD) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not isnothing(Value.CLIENT_NAME) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.CLIENT_NAME) Then .AddWithValue("@Client_Name", Value.CLIENT_NAME)
                If Not isnothing(Value.PAYMENT_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_NO) Then .AddWithValue("@payment_no", Value.PAYMENT_NO)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Year(Value.POLICY_DUE_DT) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.POLICY_DUE_DT) Then .AddWithValue("@policy_due_dt", Value.POLICY_DUE_DT)
                If Value.PAY_TAG >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAY_TAG) Then .AddWithValue("@pay_tag", Value.PAY_TAG)
                If Not isnothing(Value.PROVIDER_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_CD) Then .AddWithValue("@provider_cd", Value.PROVIDER_CD)
                If Not isnothing(Value.PRDT_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PRDT_CD) Then .AddWithValue("@prdt_cd", Value.PRDT_CD)
                If Year(Value.AR_DATE) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.AR_DATE) Then .AddWithValue("@ar_date", Value.AR_DATE)
                If Year(Value.PAYMENT_DT) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_DT) Then .AddWithValue("@payment_dt", Value.PAYMENT_DT)
                If Value.PAYMENT_AMT >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_AMT) Then .AddWithValue("@payment_amt", Value.PAYMENT_AMT)
                If Not isnothing(Value.REMARKS) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.REMARKS) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not isnothing(Value.DISPATCH_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.DISPATCH_NO) Then .AddWithValue("@dispatch_no", Value.DISPATCH_NO)
                If Not isnothing(Value.CONFIRM_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.CONFIRM_NO) Then .AddWithValue("@confirm_no", Value.CONFIRM_NO)
                If Not isnothing(Value.PAYMENT_FORM) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM) Then .AddWithValue("@payment_form", Value.PAYMENT_FORM)
                If Not isnothing(Value.PAYMENT_FORM_DESC) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM_DESC) Then .AddWithValue("@Payment_form_desc", Value.PAYMENT_FORM_DESC)
                If Not isnothing(Value.CURRENCY_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.CURRENCY_CD) Then .AddWithValue("@currency_cd", Value.CURRENCY_CD)
                If Value.CONTRIBUTION_AMT >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.CONTRIBUTION_AMT) Then .AddWithValue("@contribution_amt", Value.CONTRIBUTION_AMT)
            End With
        End Sub
        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As vw_policy_premium_dtl_rec_VO, Optional ByVal ExcludeValue As vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec = vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.None)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.POLICY_SEQ_CD) Then .Add("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.POLICY_PREMIUM_CD) Then .Add("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Not isnothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_SEQ_CD) Then .Add("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not isnothing(Value.CLIENT_NAME) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.CLIENT_NAME) Then .Add("@Client_Name", Value.CLIENT_NAME)
                If Not isnothing(Value.PAYMENT_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_NO) Then .Add("@payment_no", Value.PAYMENT_NO)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.POLICY_NO) Then .Add("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_DESC) Then .Add("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PRDT_DESC) Then .Add("@prdt_desc", Value.PRDT_DESC)
                If Year(Value.POLICY_DUE_DT) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.POLICY_DUE_DT) Then .Add("@policy_due_dt", Value.POLICY_DUE_DT)
                If Value.PAY_TAG >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAY_TAG) Then .Add("@pay_tag", Value.PAY_TAG)
                If Not isnothing(Value.PROVIDER_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PROVIDER_CD) Then .Add("@provider_cd", Value.PROVIDER_CD)
                If Not isnothing(Value.PRDT_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PRDT_CD) Then .Add("@prdt_cd", Value.PRDT_CD)
                If Year(Value.AR_DATE) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.AR_DATE) Then .Add("@ar_date", Value.AR_DATE)
                If Year(Value.PAYMENT_DT) > 1 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_DT) Then .Add("@payment_dt", Value.PAYMENT_DT)
                If Value.PAYMENT_AMT >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_AMT) Then .Add("@payment_amt", Value.PAYMENT_AMT)
                If Not isnothing(Value.REMARKS) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.REMARKS) Then .Add("@remarks", Value.REMARKS)
                If Not isnothing(Value.DISPATCH_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.DISPATCH_NO) Then .Add("@dispatch_no", Value.DISPATCH_NO)
                If Not isnothing(Value.CONFIRM_NO) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.CONFIRM_NO) Then .Add("@confirm_no", Value.CONFIRM_NO)
                If Not isnothing(Value.PAYMENT_FORM) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM) Then .Add("@payment_form", Value.PAYMENT_FORM)
                If Not isnothing(Value.PAYMENT_FORM_DESC) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.PAYMENT_FORM_DESC) Then .Add("@Payment_form_desc", Value.PAYMENT_FORM_DESC)
                If Not isnothing(Value.CURRENCY_CD) And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.CURRENCY_CD) Then .Add("@currency_cd", Value.CURRENCY_CD)
                If Value.CONTRIBUTION_AMT >= 0 And Not CheckBit(ExcludeValue, vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec.CONTRIBUTION_AMT) Then .Add("@contribution_amt", Value.CONTRIBUTION_AMT)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As vw_policy_premium_dtl_rec_VO, Optional ByVal ExcludeValue As vw_policy_premium_dtl_rec_VO.Enum_vw_policy_premium_dtl_rec = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_policy_premium_dtl_rec " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "vw_commision_payable_search"

    <Serializable()> _
    Public Class VW_COMMISION_PAYABLE_SEARCH_VO

        Public PAYMENT_SEQ_CD As String
        Public COM_PAY_SEQ_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_DUE_DT As Date
        Public POLICY_NO As String
        Public NAME As String
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public CURRENCY As String
        Public PAYMENT_AMT As Integer = -1
        Public COMP_COM_RATE As Integer = -1
        Public PAYABLE As Integer = -1
        Public COM_REC_RATE As Integer = -1
        Public COM_REC_AMT As Integer = -1
        Public SUBTOTAL As Integer = -1
        Public PAYMENT_NO As String
        Public PAYMENT_DT As Date
        Public AR_DATE As Date
        Public USER_NAME As String
        Public STATUS As String
        Public POLICY_DUE_DT_TO As Date

        Public Enum Enum_vw_commision_payable_search As Integer
            NONE = 0
            payment_seq_cd = 1
            com_pay_seq_cd = 2
            policy_seq_cd = 4
            policy_due_dt = 8
            policy_no = 16
            Name = 32
            provider_desc = 64
            prdt_desc = 128
            currency = 256
            payment_amt = 512
            comp_com_rate = 1024
            Payable = 2048
            com_rec_rate = 4096
            com_rec_amt = 8192
            Subtotal = 16384
            payment_no = 32768
            payment_dt = 65536
            ar_date = 131072
            user_name = 262144
            status = 524288
            policy_due_dt_to = 1048576
        End Enum

    End Class

    'Public POLICY_DUE_DT_TO As Date
    'policy_due_dt_to = 1048576

    Public Class VW_COMMISION_PAYABLE_SEARCH_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_commision_payable_search_VO, Optional ByVal ExcludeValue As vw_commision_payable_search_VO.Enum_vw_commision_payable_search = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_commision_payable_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_COMMISION_PAYABLE_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search = VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not isnothing(.PAYMENT_SEQ_CD) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_SEQ_CD
                If Not isnothing(.COM_PAY_SEQ_CD) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COM_PAY_SEQ_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.POLICY_SEQ_CD
                If Year(.POLICY_DUE_DT) > 1 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.POLICY_DUE_DT
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.POLICY_NO
                If Not isnothing(.NAME) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.NAME
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PROVIDER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PRDT_DESC
                If Not isnothing(.CURRENCY) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.CURRENCY
                If .PAYMENT_AMT >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_AMT
                If .COMP_COM_RATE >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COMP_COM_RATE
                If .PAYABLE >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYABLE
                If .COM_REC_RATE >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COM_REC_RATE
                If .COM_REC_AMT >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COM_REC_AMT
                If .SUBTOTAL >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.SUBTOTAL
                If Not isnothing(.PAYMENT_NO) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_NO
                If Year(.PAYMENT_DT) > 1 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_DT
                If Year(.AR_DATE) > 1 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.AR_DATE
                If Not isnothing(.USER_NAME) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.USER_NAME
                If Not IsNothing(.STATUS) Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.status
                If Year(.POLICY_DUE_DT_TO) > 1 Then shrtFlag += VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.policy_due_dt_to
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_commision_payable_search SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_commision_payable_search (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_commision_payable_search WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_SEQ_CD) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COM_PAY_SEQ_CD) Then
                            .Append("COM_PAY_SEQ_CD")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COM_PAY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.policy_due_dt) Then
                            If CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.policy_due_dt_to) Then
                                .Append("POLICY_DUE_DT BETWEEN ? AND ? ")
                                shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.policy_due_dt
                                shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.policy_due_dt_to
                                QueryType = 4
                            Else
                                .Append("POLICY_DUE_DT")
                                shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.policy_due_dt
                            End If
                            'ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.POLICY_DUE_DT) Then
                            '    .Append("POLICY_DUE_DT")
                            '    shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.POLICY_DUE_DT

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.NAME) Then
                            .Append("NAME")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.NAME

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.CURRENCY) Then
                            .Append("CURRENCY")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.CURRENCY

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_AMT) Then
                            .Append("PAYMENT_AMT")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_AMT

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COMP_COM_RATE) Then
                            .Append("COMP_COM_RATE")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COMP_COM_RATE

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYABLE) Then
                            .Append("PAYABLE")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYABLE

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COM_REC_RATE) Then
                            .Append("COM_REC_RATE")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COM_REC_RATE

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COM_REC_AMT) Then
                            .Append("COM_REC_AMT")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.COM_REC_AMT

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.SUBTOTAL) Then
                            .Append("SUBTOTAL")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.SUBTOTAL

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_NO) Then
                            .Append("PAYMENT_NO")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_NO

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_DT) Then
                            .Append("PAYMENT_DT")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.PAYMENT_DT

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.AR_DATE) Then
                            .Append("AR_DATE")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.AR_DATE

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.USER_NAME) Then
                            .Append("USER_NAME")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.USER_NAME

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.STATUS) Then
                            .Append("STATUS")
                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.STATUS

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_commision_payable_search_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_commision_payable_search_VO.Enum_vw_commision_payable_search = vw_commision_payable_search_VO.Enum_vw_commision_payable_search.None)
            With Command.Parameters
                If Not isnothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.PAYMENT_SEQ_CD) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not isnothing(Value.COM_PAY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.COM_PAY_SEQ_CD) Then .AddWithValue("@com_pay_seq_cd", Value.COM_PAY_SEQ_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Year(Value.POLICY_DUE_DT) > 1 And Not CheckBit(ExcludeValue, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.policy_due_dt) Then .AddWithValue("@policy_due_dt", Value.POLICY_DUE_DT)
                If Year(Value.POLICY_DUE_DT_TO) > 1 And Not CheckBit(ExcludeValue, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.policy_due_dt_to) Then .AddWithValue("@policy_due_dt_to", Value.POLICY_DUE_DT_TO)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.NAME) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.NAME) Then .AddWithValue("@Name", Value.NAME)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Not isnothing(Value.CURRENCY) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.CURRENCY) Then .AddWithValue("@currency", Value.CURRENCY)
                If Value.PAYMENT_AMT >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.PAYMENT_AMT) Then .AddWithValue("@payment_amt", Value.PAYMENT_AMT)
                If Value.COMP_COM_RATE >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.COMP_COM_RATE) Then .AddWithValue("@comp_com_rate", Value.COMP_COM_RATE)
                If Value.PAYABLE >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.PAYABLE) Then .AddWithValue("@Payable", Value.PAYABLE)
                If Value.COM_REC_RATE >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.COM_REC_RATE) Then .AddWithValue("@com_rec_rate", Value.COM_REC_RATE)
                If Value.COM_REC_AMT >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.COM_REC_AMT) Then .AddWithValue("@com_rec_amt", Value.COM_REC_AMT)
                If Value.SUBTOTAL >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.SUBTOTAL) Then .AddWithValue("@Subtotal", Value.SUBTOTAL)
                If Not isnothing(Value.PAYMENT_NO) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.PAYMENT_NO) Then .AddWithValue("@payment_no", Value.PAYMENT_NO)
                If Year(Value.PAYMENT_DT) > 1 And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.PAYMENT_DT) Then .AddWithValue("@payment_dt", Value.PAYMENT_DT)
                If Year(Value.AR_DATE) > 1 And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.AR_DATE) Then .AddWithValue("@ar_date", Value.AR_DATE)
                If Not isnothing(Value.USER_NAME) And Not CheckBit(ExcludeValue, vw_commision_payable_search_VO.Enum_vw_commision_payable_search.USER_NAME) Then .AddWithValue("@user_name", Value.USER_NAME)
                If Not IsNothing(Value.STATUS) And Not CheckBit(ExcludeValue, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_vw_commision_payable_search.status) Then .AddWithValue("@status", Value.STATUS)

            End With
        End Sub
        

        Public Function GetQuery(ByVal Value As vw_commision_payable_search_VO, Optional ByVal ExcludeValue As vw_commision_payable_search_VO.Enum_vw_commision_payable_search = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_commision_payable_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class


    'ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_VW_COMMISION_PAYABLE_SEARCH.policy_due_dt) Then
    '                        If CheckBit(shrtFlag, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_VW_COMMISION_PAYABLE_SEARCH.policy_due_dt_to) Then
    '                            .Append("POLICY_DUE_DT BETWEEN ? AND ? ")
    '                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_VW_COMMISION_PAYABLE_SEARCH.policy_due_dt
    '                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_VW_COMMISION_PAYABLE_SEARCH.policy_due_dt_to
    '                            QueryType = 4
    '                        Else
    '                            .Append("POLICY_DUE_DT")
    '                            shrtFlag -= VW_COMMISION_PAYABLE_SEARCH_VO.Enum_VW_COMMISION_PAYABLE_SEARCH.policy_due_dt
    '                        End If

    'If Year(Value.POLICY_DUE_DT_TO) > 1 And Not CheckBit(ExcludeValue, VW_COMMISION_PAYABLE_SEARCH_VO.Enum_VW_COMMISION_PAYABLE_SEARCH.policy_due_dt_to) Then .Add("@policy_due_dt_to", TypeCode.DateTime, Value.POLICY_DUE_DT_TO)

#End Region

#Region "vw_commision_payable_dtl"

    <Serializable()> _
    Public Class VW_COMMISION_PAYABLE_DTL_VO

        Public COM_PAY_SEQ_CD As String
        Public PAYMENT_SEQ_CD As String
        Public POLICY_SEQ_CD As String
        Public PAYMENT_NO As String
        Public PAYMENT_DT As Date
        Public AR_DATE As Date
        Public POLICY_DUE_DT As Date
        Public PAYMENT_AMT As Double = -1
        Public POLICY_NO As String
        Public COM_DT As Date
        Public ADVISOR As String
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public COMM_RATE As Double = -1
        Public COMM_PAY As Double = -1
        Public COM_REC_RATE As Double = -1
        Public COM_REC_AMT As Double = -1
        Public COM_ST As String
        Public COM_TYPE As String
        Public CURRENCY_CD As String
        Public CONV_CURR_CD As String
        Public CONV_RATE As Double = -1
        Public CONV_COM_AMT As Double = -1

        Public Enum Enum_vw_commision_payable_dtl As Integer
            NONE = 0
            com_pay_seq_cd = 1
            payment_seq_cd = 2
            policy_seq_cd = 4
            payment_no = 8
            payment_dt = 16
            ar_date = 32
            policy_due_dt = 64
            payment_amt = 128
            policy_no = 256
            com_dt = 512
            Advisor = 1024
            provider_desc = 2048
            prdt_desc = 4096
            comm_rate = 8192
            comm_pay = 16384
            com_rec_rate = 32768
            com_rec_amt = 65536
            com_st = 131072
            com_type = 262144
            currency_cd = 524288
            conv_curr_cd = 1048576
            conv_rate = 2097152
            conv_com_amt = 4194304
        End Enum

    End Class

    Public Class VW_COMMISION_PAYABLE_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_commision_payable_dtl_VO, Optional ByVal ExcludeValue As vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_commision_payable_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_COMMISION_PAYABLE_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl = VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not isnothing(.COM_PAY_SEQ_CD) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_PAY_SEQ_CD
                If Not isnothing(.PAYMENT_SEQ_CD) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_SEQ_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.POLICY_SEQ_CD
                If Not isnothing(.PAYMENT_NO) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_NO
                If Year(.PAYMENT_DT) > 1 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_DT
                If Year(.AR_DATE) > 1 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.AR_DATE
                If Year(.POLICY_DUE_DT) > 1 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.POLICY_DUE_DT
                If .PAYMENT_AMT >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_AMT
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.POLICY_NO
                If Year(.COM_DT) > 1 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_DT
                If Not isnothing(.ADVISOR) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.ADVISOR
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PROVIDER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PRDT_DESC
                If .COMM_RATE >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COMM_RATE
                If .COMM_PAY >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COMM_PAY
                If .COM_REC_RATE >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_REC_RATE
                If .COM_REC_AMT >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_REC_AMT
                If Not isnothing(.COM_ST) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_ST
                If Not isnothing(.COM_TYPE) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_TYPE
                If Not isnothing(.CURRENCY_CD) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CURRENCY_CD
                If Not isnothing(.CONV_CURR_CD) Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CONV_CURR_CD
                If .CONV_RATE >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CONV_RATE
                If .CONV_COM_AMT >= 0 Then shrtFlag += VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CONV_COM_AMT
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_commision_payable_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_commision_payable_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_commision_payable_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_PAY_SEQ_CD) Then
                            .Append("COM_PAY_SEQ_CD")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_PAY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_SEQ_CD) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_NO) Then
                            .Append("PAYMENT_NO")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_NO

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_DT) Then
                            .Append("PAYMENT_DT")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_DT

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.AR_DATE) Then
                            .Append("AR_DATE")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.AR_DATE

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.POLICY_DUE_DT) Then
                            .Append("POLICY_DUE_DT")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.POLICY_DUE_DT

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_AMT) Then
                            .Append("PAYMENT_AMT")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PAYMENT_AMT

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_DT) Then
                            .Append("COM_DT")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_DT

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.ADVISOR) Then
                            .Append("ADVISOR")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.ADVISOR

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COMM_RATE) Then
                            .Append("COMM_RATE")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COMM_RATE

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COMM_PAY) Then
                            .Append("COMM_PAY")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COMM_PAY

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_REC_RATE) Then
                            .Append("COM_REC_RATE")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_REC_RATE

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_REC_AMT) Then
                            .Append("COM_REC_AMT")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_REC_AMT

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_ST) Then
                            .Append("COM_ST")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_ST

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_TYPE) Then
                            .Append("COM_TYPE")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.COM_TYPE

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CURRENCY_CD) Then
                            .Append("CURRENCY_CD")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CURRENCY_CD

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CONV_CURR_CD) Then
                            .Append("CONV_CURR_CD")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CONV_CURR_CD

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CONV_RATE) Then
                            .Append("CONV_RATE")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CONV_RATE

                        ElseIf CheckBit(shrtFlag, VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CONV_COM_AMT) Then
                            .Append("CONV_COM_AMT")
                            shrtFlag -= VW_COMMISION_PAYABLE_DTL_VO.Enum_vw_commision_payable_dtl.CONV_COM_AMT

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_commision_payable_dtl_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl = vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.None)
            With Command.Parameters
                If Not isnothing(Value.COM_PAY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.COM_PAY_SEQ_CD) Then .AddWithValue("@com_pay_seq_cd", Value.COM_PAY_SEQ_CD)
                If Not isnothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.PAYMENT_SEQ_CD) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.PAYMENT_NO) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.PAYMENT_NO) Then .AddWithValue("@payment_no", Value.PAYMENT_NO)
                If Year(Value.PAYMENT_DT) > 1 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.PAYMENT_DT) Then .AddWithValue("@payment_dt", Value.PAYMENT_DT)
                If Year(Value.AR_DATE) > 1 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.AR_DATE) Then .AddWithValue("@ar_date", Value.AR_DATE)
                If Year(Value.POLICY_DUE_DT) > 1 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.POLICY_DUE_DT) Then .AddWithValue("@policy_due_dt", Value.POLICY_DUE_DT)
                If Value.PAYMENT_AMT >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.PAYMENT_AMT) Then .AddWithValue("@payment_amt", Value.PAYMENT_AMT)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Year(Value.COM_DT) > 1 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.COM_DT) Then .AddWithValue("@com_dt", Value.COM_DT)
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.ADVISOR) Then .AddWithValue("@Advisor", Value.ADVISOR)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Value.COMM_RATE >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.COMM_RATE) Then .AddWithValue("@comm_rate", Value.COMM_RATE)
                If Value.COMM_PAY >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.COMM_PAY) Then .AddWithValue("@comm_pay", Value.COMM_PAY)
                If Value.COM_REC_RATE >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.COM_REC_RATE) Then .AddWithValue("@com_rec_rate", Value.COM_REC_RATE)
                If Value.COM_REC_AMT >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.COM_REC_AMT) Then .AddWithValue("@com_rec_amt", Value.COM_REC_AMT)
                If Not isnothing(Value.COM_ST) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.COM_ST) Then .AddWithValue("@com_st", Value.COM_ST)
                If Not isnothing(Value.COM_TYPE) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.COM_TYPE) Then .AddWithValue("@com_type", Value.COM_TYPE)
                If Not isnothing(Value.CURRENCY_CD) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.CURRENCY_CD) Then .AddWithValue("@currency_cd", Value.CURRENCY_CD)
                If Not isnothing(Value.CONV_CURR_CD) And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.CONV_CURR_CD) Then .AddWithValue("@conv_curr_cd", Value.CONV_CURR_CD)
                If Value.CONV_RATE >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.CONV_RATE) Then .AddWithValue("@conv_rate", Value.CONV_RATE)
                If Value.CONV_COM_AMT >= 0 And Not CheckBit(ExcludeValue, vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl.CONV_COM_AMT) Then .AddWithValue("@conv_com_amt", Value.CONV_COM_AMT)
            End With
        End Sub
        Public Function GetQuery(ByVal Value As vw_commision_payable_dtl_VO, Optional ByVal ExcludeValue As vw_commision_payable_dtl_VO.Enum_vw_commision_payable_dtl = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_commision_payable_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "vw_user_cash_advance_mstr_search"

    <Serializable()> _
    Public Class VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO

        Public CASH_ADV_SEQ_CD As String
        Public ADVISOR_CD As String
        Public NAME As String
        Public CASH_ADV_DT As Date
        Public CASH_ADV_AMT As Integer = -1
        Public CASH_ADV_CURR_CD As String
        Public CURRENCY As String
        Public CASH_ADV_DT_END As Date

        Public Enum Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH As Short
            NONE = 0
            cash_adv_seq_cd = 1
            advisor_cd = 2
            Name = 4
            cash_adv_dt = 8
            cash_adv_amt = 16
            cash_adv_curr_cd = 32
            currency = 64
            cash_adv_dt_end = 128
        End Enum

    End Class

    Public Class VW_USER_CASH_ADVANCE_MSTR_SEARCH_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO, Optional ByVal ExcludeValue As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_user_cash_advance_mstr_search " & _
                                    Replace(QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike), ";", "") & _
                                    " ORDER by CASH_ADV_DT Desc"
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH = VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.CASH_ADV_SEQ_CD) Then shrtFlag += VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_seq_cd
                If Not IsNothing(.ADVISOR_CD) Then shrtFlag += VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.advisor_cd
                If Not IsNothing(.NAME) Then shrtFlag += VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.Name
                If Year(.CASH_ADV_DT) > 1 Then shrtFlag += VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt
                If .CASH_ADV_AMT >= 0 Then shrtFlag += VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_amt
                If Not IsNothing(.CASH_ADV_CURR_CD) Then shrtFlag += VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_curr_cd
                If Not IsNothing(.CURRENCY) Then shrtFlag += VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.currency
                If Year(.CASH_ADV_DT_END) > 1 Then shrtFlag += VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt_end
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_user_cash_advance_mstr_search SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_user_cash_advance_mstr_search (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_user_cash_advance_mstr_search WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_seq_cd) Then
                            .Append("CASH_ADV_SEQ_CD")
                            shrtFlag -= VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_seq_cd

                        ElseIf CheckBit(shrtFlag, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.advisor_cd) Then
                            .Append("ADVISOR_CD")
                            shrtFlag -= VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.advisor_cd

                        ElseIf CheckBit(shrtFlag, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.Name) Then
                            .Append("NAME")
                            shrtFlag -= VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.Name

                        ElseIf CheckBit(shrtFlag, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt) Then
                            If CheckBit(shrtFlag, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt_end) Then
                                .Append("CASH_ADV_DT BETWEEN ? AND ? ")
                                shrtFlag -= VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt
                                shrtFlag -= VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt_end
                                QueryType = 4
                            Else
                                .Append("CASH_ADV_DT")
                                shrtFlag -= VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt
                            End If

                        ElseIf CheckBit(shrtFlag, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_amt) Then
                            .Append("CASH_ADV_AMT")
                            shrtFlag -= VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_amt

                        ElseIf CheckBit(shrtFlag, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_curr_cd) Then
                            .Append("CASH_ADV_CURR_CD")
                            shrtFlag -= VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_curr_cd

                        ElseIf CheckBit(shrtFlag, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.currency) Then
                            .Append("CURRENCY")
                            shrtFlag -= VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.currency

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH = VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.NONE)
            With Command.Parameters
                If Not IsNothing(Value.CASH_ADV_SEQ_CD) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_seq_cd) Then .AddWithValue("@cash_adv_seq_cd", Value.CASH_ADV_SEQ_CD)
                If Not IsNothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.advisor_cd) Then .AddWithValue("@advisor_cd", Value.ADVISOR_CD)
                If Not IsNothing(Value.NAME) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.Name) Then .AddWithValue("@Name", Value.NAME)
                If Year(Value.CASH_ADV_DT) > 1 And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt) Then .AddWithValue("@cash_adv_dt", Value.CASH_ADV_DT)
                If Value.CASH_ADV_AMT >= 0 And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_amt) Then .AddWithValue("@cash_adv_amt", Value.CASH_ADV_AMT)
                If Not IsNothing(Value.CASH_ADV_CURR_CD) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_curr_cd) Then .AddWithValue("@cash_adv_curr_cd", Value.CASH_ADV_CURR_CD)
                If Not IsNothing(Value.CURRENCY) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.currency) Then .AddWithValue("@currency", Value.CURRENCY)
                If Year(Value.CASH_ADV_DT_END) > 1 And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt_end) Then .AddWithValue("@cash_adv_dt_end", Value.CASH_ADV_DT_END)
            End With
        End Sub

        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO, Optional ByVal ExcludeValue As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH = VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.NONE)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not IsNothing(Value.CASH_ADV_SEQ_CD) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_seq_cd) Then .Add("@cash_adv_seq_cd", Value.CASH_ADV_SEQ_CD)
                If Not IsNothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.advisor_cd) Then .Add("@advisor_cd", Value.ADVISOR_CD)
                If Not IsNothing(Value.NAME) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.Name) Then .Add("@Name", Value.NAME)
                If Year(Value.CASH_ADV_DT) > 1 And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_dt) Then .Add("@cash_adv_dt", Value.CASH_ADV_DT)
                If Value.CASH_ADV_AMT >= 0 And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_amt) Then .Add("@cash_adv_amt", Value.CASH_ADV_AMT)
                If Not IsNothing(Value.CASH_ADV_CURR_CD) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.cash_adv_curr_cd) Then .Add("@cash_adv_curr_cd", Value.CASH_ADV_CURR_CD)
                If Not IsNothing(Value.CURRENCY) And Not CheckBit(ExcludeValue, VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH.currency) Then .Add("@currency", Value.CURRENCY)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO, Optional ByVal ExcludeValue As VW_USER_CASH_ADVANCE_MSTR_SEARCH_VO.Enum_VW_USER_CASH_ADVANCE_MSTR_SEARCH = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_user_cash_advance_mstr_search " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "vw_rpt_policy_submit_dtl"

    <Serializable()> _
    Public Class VW_RPT_POLICY_SUBMIT_DTL_VO

        Public POLICY_SEQ_CD As String
        Public POLICY_SUBMIT_DT As Date
        Public POLICY_NO As String
        Public NAME As String
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public TEL_NO As String
        Public MOBILE_NO As String
        Public FAX_NO As String
        Public EMAIL_ADDRESS As String
        Public ADVISOR_CD As String
        Public ADVISOR As String
        Public END_DT As Date

        Public Enum Enum_VW_RPT_POLICY_SUBMIT_DTL As Short
            NONE = 0
            policy_seq_cd = 1
            policy_submit_dt = 2
            policy_no = 4
            Name = 8
            provider_desc = 16
            prdt_desc = 32
            tel_no = 64
            mobile_no = 128
            fax_no = 256
            email_address = 512
            Advisor_Cd = 1024
            Advisor = 2048
            End_DT = 4096
        End Enum

    End Class

    Public Class VW_RPT_POLICY_SUBMIT_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_rpt_policy_submit_dtl_VO, Optional ByVal ExcludeValue As vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_rpt_policy_submit_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_RPT_POLICY_SUBMIT_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl = VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_SEQ_CD
                If Year(.POLICY_SUBMIT_DT) > 1 Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_SUBMIT_DT
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_NO
                If Not isnothing(.NAME) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.NAME
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.PROVIDER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.PRDT_DESC
                If Not isnothing(.TEL_NO) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.TEL_NO
                If Not isnothing(.MOBILE_NO) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.MOBILE_NO
                If Not isnothing(.FAX_NO) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.FAX_NO
                If Not isnothing(.EMAIL_ADDRESS) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.EMAIL_ADDRESS
                If Not isnothing(.ADVISOR_CD) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.ADVISOR_CD
                If Not IsNothing(.ADVISOR) Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.Advisor
                If Year(.END_DT) > 1 Then shrtFlag += VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.End_DT
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_rpt_policy_submit_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_rpt_policy_submit_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_rpt_policy_submit_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_SEQ_CD

                            'ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_SUBMIT_DT) Then
                            '    .Append("POLICY_SUBMIT_DT")
                            '    shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_SUBMIT_DT
                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.policy_submit_dt) Then
                            If CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.End_DT) And QueryType = 0 Then
                                .Append("POLICY_SUBMIT_DT BETWEEN ? AND ? ")
                                shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.policy_submit_dt
                                shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.End_DT
                                QueryType = 4
                            Else
                                .Append("POLICY_SUBMIT_DT")
                                shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.policy_submit_dt
                            End If

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.NAME) Then
                            .Append("NAME")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.NAME

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.TEL_NO) Then
                            .Append("TEL_NO")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.TEL_NO

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.MOBILE_NO) Then
                            .Append("MOBILE_NO")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.MOBILE_NO

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.FAX_NO) Then
                            .Append("FAX_NO")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.FAX_NO

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.EMAIL_ADDRESS) Then
                            .Append("EMAIL_ADDRESS")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.EMAIL_ADDRESS

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.ADVISOR_CD) Then
                            .Append("ADVISOR_CD")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.ADVISOR_CD

                        ElseIf CheckBit(shrtFlag, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.ADVISOR) Then
                            .Append("ADVISOR")
                            shrtFlag -= VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_vw_rpt_policy_submit_dtl.ADVISOR

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_rpt_policy_submit_dtl_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl = vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Year(Value.POLICY_SUBMIT_DT) > 1 And Not CheckBit(ExcludeValue, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.policy_submit_dt) Then .AddWithValue("@policy_submit_dt", Value.POLICY_SUBMIT_DT)
                If Year(Value.END_DT) > 1 And Not CheckBit(ExcludeValue, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.End_DT) Then .AddWithValue("@End_DT", Value.END_DT)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.NAME) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.NAME) Then .AddWithValue("@Name", Value.NAME)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Not isnothing(Value.TEL_NO) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.TEL_NO) Then .AddWithValue("@tel_no", Value.TEL_NO)
                If Not isnothing(Value.MOBILE_NO) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.MOBILE_NO) Then .AddWithValue("@mobile_no", Value.MOBILE_NO)
                If Not isnothing(Value.FAX_NO) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.FAX_NO) Then .AddWithValue("@fax_no", Value.FAX_NO)
                If Not isnothing(Value.EMAIL_ADDRESS) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.EMAIL_ADDRESS) Then .AddWithValue("@email_address", Value.EMAIL_ADDRESS)
                If Not isnothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.ADVISOR_CD) Then .AddWithValue("@Advisor_Cd", Value.ADVISOR_CD)
                If Not IsNothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, VW_RPT_POLICY_SUBMIT_DTL_VO.Enum_VW_RPT_POLICY_SUBMIT_DTL.Advisor) Then .AddWithValue("@Advisor", Value.ADVISOR)

            End With
        End Sub
        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As vw_rpt_policy_submit_dtl_VO, Optional ByVal ExcludeValue As vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl = vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.None)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_SEQ_CD) Then .Add("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Year(Value.POLICY_SUBMIT_DT) > 1 And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_SUBMIT_DT) Then .Add("@policy_submit_dt", Value.POLICY_SUBMIT_DT)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.POLICY_NO) Then .Add("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.NAME) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.NAME) Then .Add("@Name", Value.NAME)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.PROVIDER_DESC) Then .Add("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.PRDT_DESC) Then .Add("@prdt_desc", Value.PRDT_DESC)
                If Not isnothing(Value.TEL_NO) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.TEL_NO) Then .Add("@tel_no", Value.TEL_NO)
                If Not isnothing(Value.MOBILE_NO) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.MOBILE_NO) Then .Add("@mobile_no", Value.MOBILE_NO)
                If Not isnothing(Value.FAX_NO) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.FAX_NO) Then .Add("@fax_no", Value.FAX_NO)
                If Not isnothing(Value.EMAIL_ADDRESS) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.EMAIL_ADDRESS) Then .Add("@email_address", Value.EMAIL_ADDRESS)
                If Not isnothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.ADVISOR_CD) Then .Add("@Advisor_Cd", Value.ADVISOR_CD)
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl.ADVISOR) Then .Add("@Advisor", Value.ADVISOR)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As vw_rpt_policy_submit_dtl_VO, Optional ByVal ExcludeValue As vw_rpt_policy_submit_dtl_VO.Enum_vw_rpt_policy_submit_dtl = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_rpt_policy_submit_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "vw_rpt_commision_journal"

    <Serializable()> _
    Public Class VW_RPT_COMMISION_JOURNAL_VO

        Public ADVISOR As String
        Public CURRENCY As String
        Public COM_DT As Date
        Public POLICY_NO As String
        Public INSURED_AMT As Integer = -1
        Public COM_AMT As Integer = -1
        Public TYPE As String
        Public STATUS As String
        Public COM_DT_END As Date

        Public Enum Enum_VW_RPT_COMMISION_JOURNAL As Short
            NONE = 0
            Advisor = 1
            Currency = 2
            com_dt = 4
            policy_no = 8
            insured_amt = 16
            com_amt = 32
            type = 64
            status = 128
            com_dt_end = 256
        End Enum

    End Class

    Public Class VW_RPT_COMMISION_JOURNAL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_rpt_commision_journal_VO, Optional ByVal ExcludeValue As vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_rpt_commision_journal " & _
                        Replace(QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike), ";", "") & _
                        " ORDER by com_dt"
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_RPT_COMMISION_JOURNAL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal = VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.ADVISOR) Then shrtFlag += VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.ADVISOR
                If Not isnothing(.CURRENCY) Then shrtFlag += VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.CURRENCY
                If Year(.COM_DT) > 1 Then shrtFlag += VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.COM_DT
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.POLICY_NO
                If .INSURED_AMT >= 0 Then shrtFlag += VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.INSURED_AMT
                If .COM_AMT >= 0 Then shrtFlag += VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.COM_AMT
                If Not isnothing(.TYPE) Then shrtFlag += VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.TYPE
                If Not IsNothing(.STATUS) Then shrtFlag += VW_RPT_COMMISION_JOURNAL_VO.Enum_VW_RPT_COMMISION_JOURNAL.status
                If Year(.COM_DT_END) > 1 Then shrtFlag += VW_RPT_COMMISION_JOURNAL_VO.Enum_VW_RPT_COMMISION_JOURNAL.com_dt_end
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_rpt_commision_journal SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_rpt_commision_journal (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_rpt_commision_journal WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.ADVISOR) Then
                            .Append("ADVISOR")
                            shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.ADVISOR

                        ElseIf CheckBit(shrtFlag, VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.CURRENCY) Then
                            .Append("CURRENCY")
                            shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.CURRENCY

                        ElseIf CheckBit(shrtFlag, VW_RPT_COMMISION_JOURNAL_VO.Enum_VW_RPT_COMMISION_JOURNAL.com_dt) Then
                            If CheckBit(shrtFlag, VW_RPT_COMMISION_JOURNAL_VO.Enum_VW_RPT_COMMISION_JOURNAL.com_dt_end) Then
                                .Append("COM_DT BETWEEN ? AND ?")
                                shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_VW_RPT_COMMISION_JOURNAL.com_dt
                                shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_VW_RPT_COMMISION_JOURNAL.com_dt_end
                                QueryType = 4
                            Else
                                .Append("COM_DT")
                                shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_VW_RPT_COMMISION_JOURNAL.com_dt
                            End If
                            

                        ElseIf CheckBit(shrtFlag, VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.INSURED_AMT) Then
                            .Append("INSURED_AMT")
                            shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.INSURED_AMT

                        ElseIf CheckBit(shrtFlag, VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.COM_AMT) Then
                            .Append("COM_AMT")
                            shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.COM_AMT

                        ElseIf CheckBit(shrtFlag, VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.TYPE) Then
                            .Append("TYPE")
                            shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.TYPE

                        ElseIf CheckBit(shrtFlag, VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.STATUS) Then
                            .Append("STATUS")
                            shrtFlag -= VW_RPT_COMMISION_JOURNAL_VO.Enum_vw_rpt_commision_journal.STATUS

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_rpt_commision_journal_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal = vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.None)
            With Command.Parameters
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.ADVISOR) Then .AddWithValue("@Advisor", Value.ADVISOR)
                If Not isnothing(Value.CURRENCY) And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.CURRENCY) Then .AddWithValue("@Currency", Value.CURRENCY)
                If Year(Value.COM_DT) > 1 And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.COM_DT) Then .AddWithValue("@com_dt", Value.COM_DT)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Value.INSURED_AMT >= 0 And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.INSURED_AMT) Then .AddWithValue("@insured_amt", Value.INSURED_AMT)
                If Value.COM_AMT >= 0 And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.COM_AMT) Then .AddWithValue("@com_amt", Value.COM_AMT)
                If Not isnothing(Value.TYPE) And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.TYPE) Then .AddWithValue("@type", Value.TYPE)
                If Not IsNothing(Value.STATUS) And Not CheckBit(ExcludeValue, VW_RPT_COMMISION_JOURNAL_VO.Enum_VW_RPT_COMMISION_JOURNAL.status) Then .AddWithValue("@status", Value.STATUS)
                If Year(Value.COM_DT_END) > 1 And Not CheckBit(ExcludeValue, VW_RPT_COMMISION_JOURNAL_VO.Enum_VW_RPT_COMMISION_JOURNAL.com_dt_end) Then .AddWithValue("@com_dt_end", Value.COM_DT_END)
            End With
        End Sub

        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As vw_rpt_commision_journal_VO, Optional ByVal ExcludeValue As vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal = vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.None)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.ADVISOR) Then .Add("@Advisor", Value.ADVISOR)
                If Not isnothing(Value.CURRENCY) And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.CURRENCY) Then .Add("@Currency", Value.CURRENCY)
                If Year(Value.COM_DT) > 1 And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.COM_DT) Then .Add("@com_dt", Value.COM_DT)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.POLICY_NO) Then .Add("@policy_no", Value.POLICY_NO)
                If Value.INSURED_AMT >= 0 And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.INSURED_AMT) Then .Add("@insured_amt", Value.INSURED_AMT)
                If Value.COM_AMT >= 0 And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.COM_AMT) Then .Add("@com_amt", Value.COM_AMT)
                If Not isnothing(Value.TYPE) And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.TYPE) Then .Add("@type", Value.TYPE)
                If Not isnothing(Value.STATUS) And Not CheckBit(ExcludeValue, vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal.STATUS) Then .Add("@status", Value.STATUS)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As vw_rpt_commision_journal_VO, Optional ByVal ExcludeValue As vw_rpt_commision_journal_VO.Enum_vw_rpt_commision_journal = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_rpt_commision_journal " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "vw_rpt_birthday_list"

    <Serializable()> _
    Public Class VW_RPT_BIRTHDAY_LIST_VO

        Public CLIENTNAME As String
        Public BIRTHDAY As Date
        Public AGE As Integer = -1
        Public TYPE As String
        Public ADVISOR As String
        Public POLICY_NO As String
        Public PROVIDER_DESC As String
        Public PRDT_DESC As String
        Public ADVISOR_CD As String
        Public POLICY_SEQ_CD As String
        Public CLIENT_CD As String
        Public POLICY_OWNER As String

        Public Enum Enum_VW_RPT_BIRTHDAY_LIST As Short
            NONE = 0
            ClientName = 1
            birthday = 2
            Age = 4
            Type = 8
            advisor = 16
            policy_no = 32
            provider_desc = 64
            prdt_desc = 128
            Advisor_Cd = 256
            policy_seq_cd = 512
            client_cd = 1024
            policy_owner = 2048
        End Enum

    End Class

    Public Class VW_RPT_BIRTHDAY_LIST_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As vw_rpt_birthday_list_VO, Optional ByVal ExcludeValue As vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM vw_rpt_birthday_list " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As VW_RPT_BIRTHDAY_LIST_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list = VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.CLIENTNAME) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.CLIENTNAME
                If Year(.BIRTHDAY) > 1 Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.BIRTHDAY
                If .AGE >= 0 Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.AGE
                If Not isnothing(.TYPE) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.TYPE
                If Not isnothing(.ADVISOR) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.ADVISOR
                If Not isnothing(.POLICY_NO) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.POLICY_NO
                If Not isnothing(.PROVIDER_DESC) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.PROVIDER_DESC
                If Not isnothing(.PRDT_DESC) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.PRDT_DESC
                If Not isnothing(.ADVISOR_CD) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.ADVISOR_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.POLICY_SEQ_CD
                If Not isnothing(.CLIENT_CD) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.CLIENT_CD
                If Not isnothing(.POLICY_OWNER) Then shrtFlag += VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.POLICY_OWNER
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE vw_rpt_birthday_list SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO vw_rpt_birthday_list (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM vw_rpt_birthday_list WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.CLIENTNAME) Then
                            .Append("CLIENTNAME")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.CLIENTNAME

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.BIRTHDAY) Then
                            .Append("BIRTHDAY")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.BIRTHDAY

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.AGE) Then
                            .Append("AGE")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.AGE

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.TYPE) Then
                            .Append("TYPE")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.TYPE

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.ADVISOR) Then
                            .Append("ADVISOR")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.ADVISOR

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.POLICY_NO

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.PROVIDER_DESC) Then
                            .Append("PROVIDER_DESC")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.PROVIDER_DESC

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.ADVISOR_CD) Then
                            .Append("ADVISOR_CD")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.ADVISOR_CD

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.CLIENT_CD) Then
                            .Append("CLIENT_CD")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.CLIENT_CD

                        ElseIf CheckBit(shrtFlag, VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.POLICY_OWNER) Then
                            .Append("POLICY_OWNER")
                            shrtFlag -= VW_RPT_BIRTHDAY_LIST_VO.Enum_vw_rpt_birthday_list.POLICY_OWNER

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As vw_rpt_birthday_list_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list = vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.None)
            With Command.Parameters
                If Not isnothing(Value.CLIENTNAME) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.CLIENTNAME) Then .AddWithValue("@ClientName", Value.CLIENTNAME)
                If Year(Value.BIRTHDAY) > 1 And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.BIRTHDAY) Then .AddWithValue("@birthday", Value.BIRTHDAY)
                If Value.AGE >= 0 And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.AGE) Then .AddWithValue("@Age", Value.AGE)
                If Not isnothing(Value.TYPE) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.TYPE) Then .AddWithValue("@Type", Value.TYPE)
                If Not isnothing(Value.ADVISOR) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.ADVISOR) Then .AddWithValue("@advisor", Value.ADVISOR)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.PROVIDER_DESC) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.PROVIDER_DESC) Then .AddWithValue("@provider_desc", Value.PROVIDER_DESC)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Not isnothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.ADVISOR_CD) Then .AddWithValue("@Advisor_Cd", Value.ADVISOR_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.CLIENT_CD) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.CLIENT_CD) Then .AddWithValue("@client_cd", Value.CLIENT_CD)
                If Not isnothing(Value.POLICY_OWNER) And Not CheckBit(ExcludeValue, vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list.POLICY_OWNER) Then .AddWithValue("@policy_owner", Value.POLICY_OWNER)
            End With
        End Sub
        Public Function GetQuery(ByVal Value As vw_rpt_birthday_list_VO, Optional ByVal ExcludeValue As vw_rpt_birthday_list_VO.Enum_vw_rpt_birthday_list = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM vw_rpt_birthday_list " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "prdt_mstr"

    <Serializable()> _
    Public Class PRDT_MSTR_VO

        Public PRDT_CD As String
        Public PRDT_DESC As String
        Public PROVIDER_CD As String
        Public PRDT_TERM As Integer = -1
        Public PRDT_PLAN_TYPE As String
        Public PRDT_COMM_RECEIVABLE As Double = -1
        Public PRDT_CREA_BY As String
        Public PRDT_CREA_DT As Date
        Public PRDT_LAST_UPD_BY As String
        Public PRDT_LAST_UPD_DT As Date

        Public Enum Enum_PRDT_MSTR As Short
            NONE = 0
            prdt_cd = 1
            prdt_desc = 2
            provider_cd = 4
            prdt_term = 8
            prdt_plan_type = 16
            prdt_comm_receivable = 32
            prdt_crea_by = 64
            prdt_crea_dt = 128
            prdt_last_upd_by = 256
            prdt_last_upd_dt = 512
        End Enum

    End Class

    Public Class PRDT_MSTR_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As prdt_mstr_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_prdt_mstr_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As prdt_mstr_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As prdt_mstr_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_prdt_mstr_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As prdt_mstr_VO, Optional ByVal ExcludeValue As prdt_mstr_VO.Enum_prdt_mstr = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM prdt_mstr " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As PRDT_MSTR_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As PRDT_MSTR_VO.Enum_prdt_mstr = PRDT_MSTR_VO.Enum_prdt_mstr.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.PRDT_CD) Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_CD
                If Not isnothing(.PRDT_DESC) Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_DESC
                If Not isnothing(.PROVIDER_CD) Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PROVIDER_CD
                If .PRDT_TERM >= 0 Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_TERM
                If Not isnothing(.PRDT_PLAN_TYPE) Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_PLAN_TYPE
                If .PRDT_COMM_RECEIVABLE >= 0 Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_COMM_RECEIVABLE
                If Not isnothing(.PRDT_CREA_BY) Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_CREA_BY
                If Year(.PRDT_CREA_DT) > 1 Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_CREA_DT
                If Not isnothing(.PRDT_LAST_UPD_BY) Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_LAST_UPD_BY
                If Year(.PRDT_LAST_UPD_DT) > 1 Then shrtFlag += PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_LAST_UPD_DT
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> PRDT_MSTR_VO.Enum_prdt_mstr.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE prdt_mstr SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO prdt_mstr (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM prdt_mstr WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_CD) Then
                            .Append("PRDT_CD")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_CD

                        ElseIf CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_DESC) Then
                            .Append("PRDT_DESC")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_DESC

                        ElseIf CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PROVIDER_CD) Then
                            .Append("PROVIDER_CD")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PROVIDER_CD

                        ElseIf CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_TERM) Then
                            .Append("PRDT_TERM")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_TERM

                        ElseIf CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_PLAN_TYPE) Then
                            .Append("PRDT_PLAN_TYPE")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_PLAN_TYPE

                        ElseIf CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_COMM_RECEIVABLE) Then
                            .Append("PRDT_COMM_RECEIVABLE")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_COMM_RECEIVABLE

                        ElseIf CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_CREA_BY) Then
                            .Append("PRDT_CREA_BY")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_CREA_BY

                        ElseIf CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_CREA_DT) Then
                            .Append("PRDT_CREA_DT")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_CREA_DT

                        ElseIf CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_LAST_UPD_BY) Then
                            .Append("PRDT_LAST_UPD_BY")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_LAST_UPD_BY

                        ElseIf CheckBit(shrtFlag, PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_LAST_UPD_DT) Then
                            .Append("PRDT_LAST_UPD_DT")
                            shrtFlag -= PRDT_MSTR_VO.Enum_prdt_mstr.PRDT_LAST_UPD_DT

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As prdt_mstr_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As prdt_mstr_VO.Enum_prdt_mstr = prdt_mstr_VO.Enum_prdt_mstr.None)
            With Command.Parameters
                If Not isnothing(Value.PRDT_CD) And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PRDT_CD) Then .AddWithValue("@prdt_cd", Value.PRDT_CD)
                If Not isnothing(Value.PRDT_DESC) And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PRDT_DESC) Then .AddWithValue("@prdt_desc", Value.PRDT_DESC)
                If Not isnothing(Value.PROVIDER_CD) And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PROVIDER_CD) Then .AddWithValue("@provider_cd", Value.PROVIDER_CD)
                If Value.PRDT_TERM >= 0 And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PRDT_TERM) Then .AddWithValue("@prdt_term", Value.PRDT_TERM)
                If Not isnothing(Value.PRDT_PLAN_TYPE) And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PRDT_PLAN_TYPE) Then .AddWithValue("@prdt_plan_type", Value.PRDT_PLAN_TYPE)
                If Value.PRDT_COMM_RECEIVABLE >= 0 And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PRDT_COMM_RECEIVABLE) Then .AddWithValue("@prdt_comm_receivable", Value.PRDT_COMM_RECEIVABLE)
                If Not isnothing(Value.PRDT_CREA_BY) And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PRDT_CREA_BY) Then .AddWithValue("@prdt_crea_by", Value.PRDT_CREA_BY)
                If Year(Value.PRDT_CREA_DT) > 1 And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PRDT_CREA_DT) Then .AddWithValue("@prdt_crea_dt", Value.PRDT_CREA_DT)
                If Not isnothing(Value.PRDT_LAST_UPD_BY) And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PRDT_LAST_UPD_BY) Then .AddWithValue("@prdt_last_upd_by", Value.PRDT_LAST_UPD_BY)
                If Year(Value.PRDT_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, prdt_mstr_VO.Enum_prdt_mstr.PRDT_LAST_UPD_DT) Then .AddWithValue("@prdt_last_upd_dt", Value.PRDT_LAST_UPD_DT)
            End With
        End Sub
        Public Function GetQuery(ByVal Value As prdt_mstr_VO, Optional ByVal ExcludeValue As prdt_mstr_VO.Enum_prdt_mstr = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM prdt_mstr " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "policy_trans"

    <Serializable()> _
    Public Class POLICY_TRANS_VO

        Public POLICY_SEQ_CD As String
        Public PLAN_TYPE As String
        Public BROKER_CD As String
        Public PROVIDER_CD As String
        Public PRDT_CD As String
        Public POLICY_NO As String
        Public POLICY_ST As String
        Public PROCESS_ST As String
        Public MEDICAL_RATE_CD As String
        Public MEDICAL_RATE_PER As Integer = -1
        Public CLIENT_TYPE As String
        Public CONTRIBUTION_AMT As Double = -1
        Public CURRENCY_CD As String
        Public INSURED_AMT As Double = -1
        Public VANISH_YRS As Double = -1
        Public VANISH_PER As Double = -1
        Public FREQUENCY_CD As String
        Public PAYMENT_CURR As String
        Public OTHERS_REQ As String
        Public CLIENT_NOTE As String
        Public POLICY_ISSUE_DT As Date
        Public POLICY_ISSUE_DT_END As Date
        Public POLICY_EFF_DT As Date
        Public POLICY_EFF_DT_END As Date
        Public CONTRIBUTION_DUE_DT As Date
        Public CONTRIBUTION_DUE_DT_END As Date
        Public POLICY_APPROVAL_DT As Date
        Public POLICY_APPROVAL_DT_END As Date
        Public ESTABLISH_PERIOD As Integer = -1
        Public COMMENCE_AGE As Integer = -1
        Public POLICY_CREA_BY As String
        Public POLICY_CREA_DT As Date
        Public POLICY_CREA_DT_END As Date
        Public POLICY_LAST_UPD_BY As String
        Public POLICY_LAST_UPD_DT As Date
        Public POLICY_LAST_UPD_DT_END As Date
        Public POLICY_REMARKS As String

        Public Enum Enum_policy_trans As Long
            NONE = 0
            policy_seq_cd = 1
            plan_type = 2
            broker_cd = 4
            provider_cd = 8
            prdt_cd = 16
            policy_no = 32
            policy_st = 64
            process_st = 128
            medical_rate_cd = 256
            medical_rate_per = 512
            client_type = 1024
            contribution_amt = 2048
            currency_cd = 4096
            insured_amt = 8192
            vanish_yrs = 16384
            vanish_per = 32768
            frequency_cd = 65536
            payment_curr = 131072
            others_req = 262144
            client_note = 524288
            policy_issue_dt = 1048576
            policy_issue_dt_END = 2097152
            policy_eff_dt = 4194304
            policy_eff_dt_END = 8388608
            contribution_due_dt = 16777216
            contribution_due_dt_END = 33554432
            policy_approval_dt = 67108864
            policy_approval_dt_END = 134217728
            establish_period = 268435456
            commence_age = 536870912
            policy_crea_by = 1073741824
            policy_crea_dt = 2147483648
            policy_crea_dt_END = 4294967296
            policy_last_upd_by = 8589934592
            policy_last_upd_dt = 17179869184
            policy_last_upd_dt_END = 34359738368
            policy_remarks = 68719476736
        End Enum

    End Class

    Public Class POLICY_TRANS_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As policy_trans_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_trans_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As policy_trans_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As policy_trans_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_trans_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As policy_trans_VO, Optional ByVal ExcludeValue As policy_trans_VO.Enum_policy_trans = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM policy_trans " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_TRANS_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_TRANS_VO.Enum_policy_trans = POLICY_TRANS_VO.Enum_policy_trans.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Long

            With Value
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_SEQ_CD
                If Not isnothing(.PLAN_TYPE) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.PLAN_TYPE
                If Not isnothing(.BROKER_CD) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.BROKER_CD
                If Not isnothing(.PROVIDER_CD) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.PROVIDER_CD
                If Not isnothing(.PRDT_CD) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.PRDT_CD
                If Not isnothing(.POLICY_NO) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_NO
                If Not isnothing(.POLICY_ST) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_ST
                If Not isnothing(.PROCESS_ST) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.PROCESS_ST
                If Not isnothing(.MEDICAL_RATE_CD) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.MEDICAL_RATE_CD
                If .MEDICAL_RATE_PER >= 0 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.MEDICAL_RATE_PER
                If Not isnothing(.CLIENT_TYPE) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.CLIENT_TYPE
                If .CONTRIBUTION_AMT >= 0 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.CONTRIBUTION_AMT
                If Not isnothing(.CURRENCY_CD) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.CURRENCY_CD
                If .INSURED_AMT >= 0 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.INSURED_AMT
                If .VANISH_YRS >= 0 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.VANISH_YRS
                If .VANISH_PER >= 0 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.VANISH_PER
                If Not isnothing(.FREQUENCY_CD) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.FREQUENCY_CD
                If Not isnothing(.PAYMENT_CURR) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.PAYMENT_CURR
                If Not isnothing(.OTHERS_REQ) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.OTHERS_REQ
                If Not isnothing(.CLIENT_NOTE) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.CLIENT_NOTE
                If Year(.POLICY_ISSUE_DT) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_ISSUE_DT
                If Year(.POLICY_ISSUE_DT_END) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_ISSUE_DT_END
                If Year(.POLICY_EFF_DT) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_EFF_DT
                If Year(.POLICY_EFF_DT_END) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_EFF_DT_END
                If Year(.CONTRIBUTION_DUE_DT) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.CONTRIBUTION_DUE_DT
                If Year(.CONTRIBUTION_DUE_DT_END) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.CONTRIBUTION_DUE_DT_END
                If Year(.POLICY_APPROVAL_DT) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_APPROVAL_DT
                If Year(.POLICY_APPROVAL_DT_END) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_APPROVAL_DT_END
                If .ESTABLISH_PERIOD >= 0 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.ESTABLISH_PERIOD
                If .COMMENCE_AGE >= 0 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.COMMENCE_AGE
                If Not isnothing(.POLICY_CREA_BY) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_CREA_BY
                If Year(.POLICY_CREA_DT) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_CREA_DT
                If Year(.POLICY_CREA_DT_END) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_CREA_DT_END
                If Not isnothing(.POLICY_LAST_UPD_BY) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_LAST_UPD_BY
                If Year(.POLICY_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_LAST_UPD_DT
                If Year(.POLICY_LAST_UPD_DT_END) > 1 Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_LAST_UPD_DT_END
                If Not isnothing(.POLICY_REMARKS) Then shrtFlag += POLICY_TRANS_VO.Enum_policy_trans.POLICY_REMARKS
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_TRANS_VO.Enum_policy_trans.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE policy_trans SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO policy_trans (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM policy_trans WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.PLAN_TYPE) Then
                            .Append("PLAN_TYPE")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.PLAN_TYPE

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.BROKER_CD) Then
                            .Append("BROKER_CD")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.BROKER_CD

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.PROVIDER_CD) Then
                            .Append("PROVIDER_CD")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.PROVIDER_CD

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.PRDT_CD) Then
                            .Append("PRDT_CD")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.PRDT_CD

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_NO) Then
                            .Append("POLICY_NO")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_NO

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_ST) Then
                            .Append("POLICY_ST")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_ST

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.PROCESS_ST) Then
                            .Append("PROCESS_ST")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.PROCESS_ST

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.MEDICAL_RATE_CD) Then
                            .Append("MEDICAL_RATE_CD")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.MEDICAL_RATE_CD

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.MEDICAL_RATE_PER) Then
                            .Append("MEDICAL_RATE_PER")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.MEDICAL_RATE_PER

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.CLIENT_TYPE) Then
                            .Append("CLIENT_TYPE")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.CLIENT_TYPE

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.CONTRIBUTION_AMT) Then
                            .Append("CONTRIBUTION_AMT")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.CONTRIBUTION_AMT

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.CURRENCY_CD) Then
                            .Append("CURRENCY_CD")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.CURRENCY_CD

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.INSURED_AMT) Then
                            .Append("INSURED_AMT")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.INSURED_AMT

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.VANISH_YRS) Then
                            .Append("VANISH_YRS")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.VANISH_YRS

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.VANISH_PER) Then
                            .Append("VANISH_PER")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.VANISH_PER

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.FREQUENCY_CD) Then
                            .Append("FREQUENCY_CD")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.FREQUENCY_CD

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.PAYMENT_CURR) Then
                            .Append("PAYMENT_CURR")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.PAYMENT_CURR

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.OTHERS_REQ) Then
                            .Append("OTHERS_REQ")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.OTHERS_REQ

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.CLIENT_NOTE) Then
                            .Append("CLIENT_NOTE")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.CLIENT_NOTE

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_ISSUE_DT) Then
                            If CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_ISSUE_DT_END) Then
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_ISSUE_DT
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_ISSUE_DT_END
                                .Append(" POLICY_ISSUE_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_EFF_DT) Then
                            If CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_EFF_DT_END) Then
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_EFF_DT
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_EFF_DT_END
                                .Append(" POLICY_EFF_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.CONTRIBUTION_DUE_DT) Then
                            If CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.CONTRIBUTION_DUE_DT_END) Then
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.CONTRIBUTION_DUE_DT
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.CONTRIBUTION_DUE_DT_END
                                .Append(" CONTRIBUTION_DUE_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_APPROVAL_DT) Then
                            If CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_APPROVAL_DT_END) Then
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_APPROVAL_DT
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_APPROVAL_DT_END
                                .Append(" POLICY_APPROVAL_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.ESTABLISH_PERIOD) Then
                            .Append("ESTABLISH_PERIOD")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.ESTABLISH_PERIOD

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.COMMENCE_AGE) Then
                            .Append("COMMENCE_AGE")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.COMMENCE_AGE

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_CREA_BY) Then
                            .Append("POLICY_CREA_BY")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_CREA_BY

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_CREA_DT) Then
                            If CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_CREA_DT_END) Then
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_CREA_DT
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_CREA_DT_END
                                .Append(" POLICY_CREA_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_LAST_UPD_BY) Then
                            .Append("POLICY_LAST_UPD_BY")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_LAST_UPD_BY

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_LAST_UPD_DT) Then
                            If CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_LAST_UPD_DT_END) Then
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_LAST_UPD_DT
                                shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_LAST_UPD_DT_END
                                .Append(" POLICY_LAST_UPD_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_VO.Enum_policy_trans.POLICY_REMARKS) Then
                            .Append("POLICY_REMARKS")
                            shrtFlag -= POLICY_TRANS_VO.Enum_policy_trans.POLICY_REMARKS

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As policy_trans_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As policy_trans_VO.Enum_policy_trans = policy_trans_VO.Enum_policy_trans.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.PLAN_TYPE) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.PLAN_TYPE) Then .AddWithValue("@plan_type", Value.PLAN_TYPE)
                If Not isnothing(Value.BROKER_CD) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.BROKER_CD) Then .AddWithValue("@broker_cd", Value.BROKER_CD)
                If Not isnothing(Value.PROVIDER_CD) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.PROVIDER_CD) Then .AddWithValue("@provider_cd", Value.PROVIDER_CD)
                If Not isnothing(Value.PRDT_CD) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.PRDT_CD) Then .AddWithValue("@prdt_cd", Value.PRDT_CD)
                If Not isnothing(Value.POLICY_NO) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_NO) Then .AddWithValue("@policy_no", Value.POLICY_NO)
                If Not isnothing(Value.POLICY_ST) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_ST) Then .AddWithValue("@policy_st", Value.POLICY_ST)
                If Not isnothing(Value.PROCESS_ST) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.PROCESS_ST) Then .AddWithValue("@process_st", Value.PROCESS_ST)
                If Not isnothing(Value.MEDICAL_RATE_CD) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.MEDICAL_RATE_CD) Then .AddWithValue("@medical_rate_cd", Value.MEDICAL_RATE_CD)
                If Value.MEDICAL_RATE_PER >= 0 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.MEDICAL_RATE_PER) Then .AddWithValue("@medical_rate_per", Value.MEDICAL_RATE_PER)
                If Not isnothing(Value.CLIENT_TYPE) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.CLIENT_TYPE) Then .AddWithValue("@client_type", Value.CLIENT_TYPE)
                If Value.CONTRIBUTION_AMT >= 0 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.CONTRIBUTION_AMT) Then .AddWithValue("@contribution_amt", Value.CONTRIBUTION_AMT)
                If Not isnothing(Value.CURRENCY_CD) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.CURRENCY_CD) Then .AddWithValue("@currency_cd", Value.CURRENCY_CD)
                If Value.INSURED_AMT >= 0 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.INSURED_AMT) Then .AddWithValue("@insured_amt", Value.INSURED_AMT)
                If Value.VANISH_YRS >= 0 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.VANISH_YRS) Then .AddWithValue("@vanish_yrs", Value.VANISH_YRS)
                If Value.VANISH_PER >= 0 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.VANISH_PER) Then .AddWithValue("@vanish_per", Value.VANISH_PER)
                If Not isnothing(Value.FREQUENCY_CD) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.FREQUENCY_CD) Then .AddWithValue("@frequency_cd", Value.FREQUENCY_CD)
                If Not isnothing(Value.PAYMENT_CURR) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.PAYMENT_CURR) Then .AddWithValue("@payment_curr", Value.PAYMENT_CURR)
                If Not isnothing(Value.OTHERS_REQ) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.OTHERS_REQ) Then .AddWithValue("@others_req", Value.OTHERS_REQ)
                If Not isnothing(Value.CLIENT_NOTE) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.CLIENT_NOTE) Then .AddWithValue("@client_note", Value.CLIENT_NOTE)
                If Year(Value.POLICY_ISSUE_DT) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_ISSUE_DT) Then .AddWithValue("@policy_issue_dt", Value.POLICY_ISSUE_DT)
                If Year(Value.POLICY_ISSUE_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_ISSUE_DT_END) Then .AddWithValue("@policy_issue_dt_END", Value.POLICY_ISSUE_DT_END)
                If Year(Value.POLICY_EFF_DT) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_EFF_DT) Then .AddWithValue("@policy_eff_dt", Value.POLICY_EFF_DT)
                If Year(Value.POLICY_EFF_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_EFF_DT_END) Then .AddWithValue("@policy_eff_dt_END", Value.POLICY_EFF_DT_END)
                If Year(Value.CONTRIBUTION_DUE_DT) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.CONTRIBUTION_DUE_DT) Then .AddWithValue("@contribution_due_dt", Value.CONTRIBUTION_DUE_DT)
                If Year(Value.CONTRIBUTION_DUE_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.CONTRIBUTION_DUE_DT_END) Then .AddWithValue("@contribution_due_dt_END", Value.CONTRIBUTION_DUE_DT_END)
                If Year(Value.POLICY_APPROVAL_DT) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_APPROVAL_DT) Then .AddWithValue("@policy_approval_dt", Value.POLICY_APPROVAL_DT)
                If Year(Value.POLICY_APPROVAL_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_APPROVAL_DT_END) Then .AddWithValue("@policy_approval_dt_END", Value.POLICY_APPROVAL_DT_END)
                If Value.ESTABLISH_PERIOD >= 0 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.ESTABLISH_PERIOD) Then .AddWithValue("@establish_period", Value.ESTABLISH_PERIOD)
                If Value.COMMENCE_AGE >= 0 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.COMMENCE_AGE) Then .AddWithValue("@commence_age", Value.COMMENCE_AGE)
                If Not isnothing(Value.POLICY_CREA_BY) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_CREA_BY) Then .AddWithValue("@policy_crea_by", Value.POLICY_CREA_BY)
                If Year(Value.POLICY_CREA_DT) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_CREA_DT) Then .AddWithValue("@policy_crea_dt", Value.POLICY_CREA_DT)
                If Year(Value.POLICY_CREA_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_CREA_DT_END) Then .AddWithValue("@policy_crea_dt_END", Value.POLICY_CREA_DT_END)
                If Not isnothing(Value.POLICY_LAST_UPD_BY) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_LAST_UPD_BY) Then .AddWithValue("@policy_last_upd_by", Value.POLICY_LAST_UPD_BY)
                If Year(Value.POLICY_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_LAST_UPD_DT) Then .AddWithValue("@policy_last_upd_dt", Value.POLICY_LAST_UPD_DT)
                If Year(Value.POLICY_LAST_UPD_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_LAST_UPD_DT_END) Then .AddWithValue("@policy_last_upd_dt_END", Value.POLICY_LAST_UPD_DT_END)
                If Not isnothing(Value.POLICY_REMARKS) And Not CheckBit(ExcludeValue, policy_trans_VO.Enum_policy_trans.POLICY_REMARKS) Then .AddWithValue("@policy_remarks", Value.POLICY_REMARKS)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As policy_trans_VO, Optional ByVal ExcludeValue As policy_trans_VO.Enum_policy_trans = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM policy_trans " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "policy_client_dtl_main"

    <Serializable()> _
    Public Class POLICY_CLIENT_DTL_VO_MAIN

        Public POLICY_CLIENT_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_CLIENT_LAST_NAME As String
        Public POLICY_CLIENT_FIRST_NAME As String
        Public POLICY_CLIENT_MIDDLE_NAME As String
        Public POLICY_CLIENT_SALUTATION As String
        Public POLICY_CLIENT_ALIAS As String
        Public MARITAL_ST As String
        Public GENDER As String
        Public BIRTHDAY As Date
        Public BIRTHPLACE As String
        Public POLICY_CLIENT_ADDRESS As String
        Public POLICY_CLIENT_ADDRESS2 As String
        Public CITY_CD As String
        Public COUNTRY_CD As String
        Public ZIP_CD As String
        Public NATIONALITY_CD As String
        Public RESIDENCY As Integer = -1
        Public TEL_NO As String
        Public MOBILE_NO As String
        Public FAX_NO As String
        Public NET_WORTH As Integer = -1
        Public EMP_INCOME As Integer = -1
        Public EMAIL_ADDRESS As String
        Public INSURED_TAG As Integer = -1
        Public OWNER_TAG As Integer = -1
        Public POLICY_CLIENT_CREA_BY As String
        Public POLICY_CLIENT_CREA_DT As Date
        Public POLICY_CLIENT_LAST_UPD_BY As String
        Public POLICY_CLIENT_LAST_UPD_DT As Date

        Public Enum Enum_policy_client_dtl_main As Long
            NONE = 0
            policy_client_cd = 1
            policy_seq_cd = 2
            policy_client_last_name = 4
            policy_client_first_name = 8
            policy_client_middle_name = 16
            policy_client_salutation = 32
            policy_client_alias = 64
            marital_st = 128
            gender = 256
            birthday = 512
            birthplace = 1024
            policy_client_address = 2048
            policy_client_address2 = 4096
            city_cd = 8192
            country_cd = 16384
            zip_cd = 32768
            nationality_cd = 65536
            residency = 131072
            tel_no = 262144
            mobile_no = 524288
            fax_no = 1048576
            net_worth = 2097152
            emp_income = 4194304
            email_address = 8388608
            insured_tag = 16777216
            owner_tag = 33554432
            policy_client_crea_by = 67108864
            policy_client_crea_dt = 134217728
            policy_client_last_upd_by = 268435456
            policy_client_last_upd_dt = 536870912
        End Enum

    End Class

    Public Class POLICY_CLIENT_DTL_DAO_MAIN
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_CLIENT_DTL_VO_MAIN) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_client_dtl_ins_main"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_CLIENT_DTL_VO_MAIN) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_CLIENT_DTL_VO_MAIN) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_client_dtl_upd_main"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_CLIENT_DTL_VO_MAIN, Optional ByVal ExcludeValue As POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM policy_client_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_CLIENT_DTL_VO_MAIN, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main = POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Long

            With Value
                If Not IsNothing(.POLICY_CLIENT_CD) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_seq_cd
                If Not IsNothing(.POLICY_CLIENT_LAST_NAME) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_name
                If Not IsNothing(.POLICY_CLIENT_FIRST_NAME) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_first_name
                If Not IsNothing(.POLICY_CLIENT_MIDDLE_NAME) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_middle_name
                If Not IsNothing(.POLICY_CLIENT_SALUTATION) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_salutation
                If Not IsNothing(.POLICY_CLIENT_ALIAS) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_alias
                If Not IsNothing(.MARITAL_ST) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.marital_st
                If Not IsNothing(.GENDER) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.gender
                If Year(.BIRTHDAY) > 1 Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthday
                If Not IsNothing(.BIRTHPLACE) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthplace
                If Not IsNothing(.POLICY_CLIENT_ADDRESS) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address
                If Not IsNothing(.POLICY_CLIENT_ADDRESS2) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address2
                If Not IsNothing(.CITY_CD) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.city_cd
                If Not IsNothing(.COUNTRY_CD) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.country_cd
                If Not IsNothing(.ZIP_CD) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.zip_cd
                If Not IsNothing(.NATIONALITY_CD) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.nationality_cd
                If .RESIDENCY >= 0 Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.residency
                If Not IsNothing(.TEL_NO) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.tel_no
                If Not IsNothing(.MOBILE_NO) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.mobile_no
                If Not IsNothing(.FAX_NO) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.fax_no
                If .NET_WORTH >= 0 Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.net_worth
                If .EMP_INCOME >= 0 Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.emp_income
                If Not IsNothing(.EMAIL_ADDRESS) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.email_address
                If .INSURED_TAG >= 0 Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.insured_tag
                If .OWNER_TAG >= 0 Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.owner_tag
                If Not IsNothing(.POLICY_CLIENT_CREA_BY) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_by
                If Year(.POLICY_CLIENT_CREA_DT) > 1 Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_dt
                If Not IsNothing(.POLICY_CLIENT_LAST_UPD_BY) Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_by
                If Year(.POLICY_CLIENT_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE policy_client_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO policy_client_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM policy_client_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_cd) Then
                            .Append("POLICY_CLIENT_CD")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_name) Then
                            .Append("POLICY_CLIENT_LAST_NAME")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_name

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_first_name) Then
                            .Append("POLICY_CLIENT_FIRST_NAME")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_first_name

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_middle_name) Then
                            .Append("POLICY_CLIENT_MIDDLE_NAME")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_middle_name

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_salutation) Then
                            .Append("POLICY_CLIENT_SALUTATION")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_salutation

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_alias) Then
                            .Append("POLICY_CLIENT_ALIAS")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_alias

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.marital_st) Then
                            .Append("MARITAL_ST")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.marital_st

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.gender) Then
                            .Append("GENDER")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.gender

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthday) Then
                            .Append("BIRTHDAY")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthday

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthplace) Then
                            .Append("BIRTHPLACE")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthplace

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address) Then
                            .Append("POLICY_CLIENT_ADDRESS")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address2) Then
                            .Append("POLICY_CLIENT_ADDRESS2")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address2

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.city_cd) Then
                            .Append("CITY_CD")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.city_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.country_cd) Then
                            .Append("COUNTRY_CD")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.country_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.zip_cd) Then
                            .Append("ZIP_CD")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.zip_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.nationality_cd) Then
                            .Append("NATIONALITY_CD")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.nationality_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.residency) Then
                            .Append("RESIDENCY")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.residency

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.tel_no) Then
                            .Append("TEL_NO")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.tel_no

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.mobile_no) Then
                            .Append("MOBILE_NO")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.mobile_no

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.fax_no) Then
                            .Append("FAX_NO")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.fax_no

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.net_worth) Then
                            .Append("NET_WORTH")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.net_worth

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.emp_income) Then
                            .Append("EMP_INCOME")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.emp_income

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.email_address) Then
                            .Append("EMAIL_ADDRESS")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.email_address

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.insured_tag) Then
                            .Append("INSURED_TAG")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.insured_tag

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.owner_tag) Then
                            .Append("OWNER_TAG")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.owner_tag

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_by) Then
                            .Append("POLICY_CLIENT_CREA_BY")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_dt) Then
                            .Append("POLICY_CLIENT_CREA_DT")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_by) Then
                            .Append("POLICY_CLIENT_LAST_UPD_BY")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_dt) Then
                            .Append("POLICY_CLIENT_LAST_UPD_DT")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_CLIENT_DTL_VO_MAIN, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main = POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_CLIENT_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_cd) Then .AddWithValue("@policy_client_cd", Value.POLICY_CLIENT_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.POLICY_CLIENT_LAST_NAME) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_name) Then .AddWithValue("@policy_client_last_name", Value.POLICY_CLIENT_LAST_NAME)
                If Not IsNothing(Value.POLICY_CLIENT_FIRST_NAME) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_first_name) Then .AddWithValue("@policy_client_first_name", Value.POLICY_CLIENT_FIRST_NAME)
                If Not IsNothing(Value.POLICY_CLIENT_MIDDLE_NAME) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_middle_name) Then .AddWithValue("@policy_client_middle_name", Value.POLICY_CLIENT_MIDDLE_NAME)
                If Not IsNothing(Value.POLICY_CLIENT_SALUTATION) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_salutation) Then .AddWithValue("@policy_client_salutation", Value.POLICY_CLIENT_SALUTATION)
                If Not IsNothing(Value.POLICY_CLIENT_ALIAS) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_alias) Then .AddWithValue("@policy_client_alias", Value.POLICY_CLIENT_ALIAS)
                If Not IsNothing(Value.MARITAL_ST) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.marital_st) Then .AddWithValue("@marital_st", Value.MARITAL_ST)
                If Not IsNothing(Value.GENDER) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.gender) Then .AddWithValue("@gender", Value.GENDER)
                If Year(Value.BIRTHDAY) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthday) Then .AddWithValue("@birthday", Value.BIRTHDAY)
                If Not IsNothing(Value.BIRTHPLACE) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthplace) Then .AddWithValue("@birthplace", Value.BIRTHPLACE)
                If Not IsNothing(Value.POLICY_CLIENT_ADDRESS) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address) Then .AddWithValue("@policy_client_address", Value.POLICY_CLIENT_ADDRESS)
                If Not IsNothing(Value.POLICY_CLIENT_ADDRESS2) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address2) Then .AddWithValue("@policy_client_address2", Value.POLICY_CLIENT_ADDRESS2)
                If Not IsNothing(Value.CITY_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.city_cd) Then .AddWithValue("@city_cd", Value.CITY_CD)
                If Not IsNothing(Value.COUNTRY_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.country_cd) Then .AddWithValue("@country_cd", Value.COUNTRY_CD)
                If Not IsNothing(Value.ZIP_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.zip_cd) Then .AddWithValue("@zip_cd", Value.ZIP_CD)
                If Not IsNothing(Value.NATIONALITY_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.nationality_cd) Then .AddWithValue("@nationality_cd", Value.NATIONALITY_CD)
                If Value.RESIDENCY >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.residency) Then .AddWithValue("@residency", Value.RESIDENCY)
                If Not IsNothing(Value.TEL_NO) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.tel_no) Then .AddWithValue("@tel_no", Value.TEL_NO)
                If Not IsNothing(Value.MOBILE_NO) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.mobile_no) Then .AddWithValue("@mobile_no", Value.MOBILE_NO)
                If Not IsNothing(Value.FAX_NO) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.fax_no) Then .AddWithValue("@fax_no", Value.FAX_NO)
                If Value.NET_WORTH >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.net_worth) Then .AddWithValue("@net_worth", Value.NET_WORTH)
                If Value.EMP_INCOME >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.emp_income) Then .AddWithValue("@emp_income", Value.EMP_INCOME)
                If Not IsNothing(Value.EMAIL_ADDRESS) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.email_address) Then .AddWithValue("@email_address", Value.EMAIL_ADDRESS)
                If Value.INSURED_TAG >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.insured_tag) Then .AddWithValue("@insured_tag", Value.INSURED_TAG)
                If Value.OWNER_TAG >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.owner_tag) Then .AddWithValue("@owner_tag", Value.OWNER_TAG)
                If Not IsNothing(Value.POLICY_CLIENT_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_by) Then .AddWithValue("@policy_client_crea_by", Value.POLICY_CLIENT_CREA_BY)
                If Year(Value.POLICY_CLIENT_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_dt) Then .AddWithValue("@policy_client_crea_dt", Value.POLICY_CLIENT_CREA_DT)
                If Not IsNothing(Value.POLICY_CLIENT_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_by) Then .AddWithValue("@policy_client_last_upd_by", Value.POLICY_CLIENT_LAST_UPD_BY)
                If Year(Value.POLICY_CLIENT_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_dt) Then .AddWithValue("@policy_client_last_upd_dt", Value.POLICY_CLIENT_LAST_UPD_DT)
            End With
        End Sub
        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As POLICY_CLIENT_DTL_VO_MAIN, Optional ByVal ExcludeValue As POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main = POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.NONE)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not IsNothing(Value.POLICY_CLIENT_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_cd) Then .Add("@policy_client_cd", Value.POLICY_CLIENT_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_seq_cd) Then .Add("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.POLICY_CLIENT_LAST_NAME) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_name) Then .Add("@policy_client_last_name", Value.POLICY_CLIENT_LAST_NAME)
                If Not IsNothing(Value.POLICY_CLIENT_FIRST_NAME) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_first_name) Then .Add("@policy_client_first_name", Value.POLICY_CLIENT_FIRST_NAME)
                If Not IsNothing(Value.POLICY_CLIENT_MIDDLE_NAME) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_middle_name) Then .Add("@policy_client_middle_name", Value.POLICY_CLIENT_MIDDLE_NAME)
                If Not IsNothing(Value.POLICY_CLIENT_SALUTATION) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_salutation) Then .Add("@policy_client_salutation", Value.POLICY_CLIENT_SALUTATION)
                If Not IsNothing(Value.POLICY_CLIENT_ALIAS) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_alias) Then .Add("@policy_client_alias", Value.POLICY_CLIENT_ALIAS)
                If Not IsNothing(Value.MARITAL_ST) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.marital_st) Then .Add("@marital_st", Value.MARITAL_ST)
                If Not IsNothing(Value.GENDER) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.gender) Then .Add("@gender", Value.GENDER)
                If Year(Value.BIRTHDAY) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthday) Then .Add("@birthday", Value.BIRTHDAY)
                If Not IsNothing(Value.BIRTHPLACE) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.birthplace) Then .Add("@birthplace", Value.BIRTHPLACE)
                If Not IsNothing(Value.POLICY_CLIENT_ADDRESS) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address) Then .Add("@policy_client_address", Value.POLICY_CLIENT_ADDRESS)
                If Not IsNothing(Value.POLICY_CLIENT_ADDRESS2) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_address2) Then .Add("@policy_client_address2", Value.POLICY_CLIENT_ADDRESS2)
                If Not IsNothing(Value.CITY_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.city_cd) Then .Add("@city_cd", Value.CITY_CD)
                If Not IsNothing(Value.COUNTRY_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.country_cd) Then .Add("@country_cd", Value.COUNTRY_CD)
                If Not IsNothing(Value.ZIP_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.zip_cd) Then .Add("@zip_cd", Value.ZIP_CD)
                If Not IsNothing(Value.NATIONALITY_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.nationality_cd) Then .Add("@nationality_cd", Value.NATIONALITY_CD)
                If Value.RESIDENCY >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.residency) Then .Add("@residency", Value.RESIDENCY)
                If Not IsNothing(Value.TEL_NO) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.tel_no) Then .Add("@tel_no", Value.TEL_NO)
                If Not IsNothing(Value.MOBILE_NO) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.mobile_no) Then .Add("@mobile_no", Value.MOBILE_NO)
                If Not IsNothing(Value.FAX_NO) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.fax_no) Then .Add("@fax_no", Value.FAX_NO)
                If Value.NET_WORTH >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.net_worth) Then .Add("@net_worth", Value.NET_WORTH)
                If Value.EMP_INCOME >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.emp_income) Then .Add("@emp_income", Value.EMP_INCOME)
                If Not IsNothing(Value.EMAIL_ADDRESS) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.email_address) Then .Add("@email_address", Value.EMAIL_ADDRESS)
                If Value.INSURED_TAG >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.insured_tag) Then .Add("@insured_tag", Value.INSURED_TAG)
                If Value.OWNER_TAG >= 0 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.owner_tag) Then .Add("@owner_tag", Value.OWNER_TAG)
                If Not IsNothing(Value.POLICY_CLIENT_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_by) Then .Add("@policy_client_crea_by", Value.POLICY_CLIENT_CREA_BY)
                If Year(Value.POLICY_CLIENT_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_crea_dt) Then .Add("@policy_client_crea_dt", Value.POLICY_CLIENT_CREA_DT)
                If Not IsNothing(Value.POLICY_CLIENT_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_by) Then .Add("@policy_client_last_upd_by", Value.POLICY_CLIENT_LAST_UPD_BY)
                If Year(Value.POLICY_CLIENT_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main.policy_client_last_upd_dt) Then .Add("@policy_client_last_upd_dt", Value.POLICY_CLIENT_LAST_UPD_DT)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As POLICY_CLIENT_DTL_VO_MAIN, Optional ByVal ExcludeValue As POLICY_CLIENT_DTL_VO_MAIN.Enum_policy_client_dtl_main = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM policy_client_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "policy_client_dtl_other"
    <Serializable()> _
    Public Class POLICY_CLIENT_DTL_VO_OTHER

        Public POLICY_CLIENT_CD As String
        Public POLICY_SEQ_CD As String
        Public OCCUPATION As String
        Public POLICY_CLIENT_POSITION As String
        Public BUSINESS_NATURE As String
        Public ID_TYPE As String
        Public ID_NO As String
        Public SOURCE_FUND As String
        Public SMOKE_ST As String
        Public REMARKS As String
        Public POLICY_CLIENT_CREA_BY As String
        Public POLICY_CLIENT_CREA_DT As Date
        Public POLICY_CLIENT_LAST_UPD_BY As String
        Public POLICY_CLIENT_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_CLIENT_DTL_other As Short
            NONE = 0
            policy_client_cd = 1
            policy_seq_cd = 2
            occupation = 4
            policy_client_position = 8
            business_nature = 16
            id_type = 32
            id_no = 64
            source_fund = 128
            smoke_st = 256
            remarks = 512
            policy_client_crea_by = 1024
            policy_client_crea_dt = 2048
            policy_client_last_upd_by = 4096
            policy_client_last_upd_dt = 8192
        End Enum

    End Class


    Public Class POLICY_CLIENT_DTL_DAO_OTHER
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_CLIENT_DTL_VO_OTHER) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_client_dtl_ins_other"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_CLIENT_DTL_VO_OTHER) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_CLIENT_DTL_VO_OTHER) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_client_dtl_upd_other"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_CLIENT_DTL_VO_OTHER, Optional ByVal ExcludeValue As POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM POLICY_CLIENT_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_CLIENT_DTL_VO_OTHER, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other = POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Long

            With Value
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_cd
                Else
                    If .POLICY_CLIENT_CD <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_cd
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_seq_cd
                Else
                    If .POLICY_SEQ_CD <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_seq_cd
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.occupation
                Else
                    If .OCCUPATION <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.occupation
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_position
                Else
                    If .POLICY_CLIENT_POSITION <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_position
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.business_nature
                Else
                    If .BUSINESS_NATURE <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.business_nature
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_type
                Else
                    If .ID_TYPE <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_type
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_no
                Else
                    If .ID_NO <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_no
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.source_fund
                Else
                    If .SOURCE_FUND <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.source_fund
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.smoke_st
                Else
                    If .SMOKE_ST <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.smoke_st
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.remarks
                Else
                    If .REMARKS <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.remarks
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_crea_by
                Else
                    If .POLICY_CLIENT_CREA_BY <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_crea_by
                End If
                If Year(.POLICY_CLIENT_CREA_DT) > 1 Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_crea_dt
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_last_upd_by
                Else
                    If .POLICY_CLIENT_LAST_UPD_BY <> "" Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_last_upd_by
                End If
                If Year(.POLICY_CLIENT_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE POLICY_CLIENT_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO POLICY_CLIENT_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM POLICY_CLIENT_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_cd) Then
                            .Append("POLICY_CLIENT_CD")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.occupation) Then
                            .Append("OCCUPATION")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.occupation

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_position) Then
                            .Append("POLICY_CLIENT_POSITION")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_position

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.business_nature) Then
                            .Append("BUSINESS_NATURE")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.business_nature

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_type) Then
                            .Append("ID_TYPE")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_type

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_no) Then
                            .Append("ID_NO")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_no

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.source_fund) Then
                            .Append("SOURCE_FUND")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.source_fund

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.smoke_st) Then
                            .Append("SMOKE_ST")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.smoke_st

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.remarks) Then
                            .Append("REMARKS")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.remarks

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_crea_by) Then
                            .Append("POLICY_CLIENT_CREA_BY")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_crea_dt) Then
                            .Append("POLICY_CLIENT_CREA_DT")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_last_upd_by) Then
                            .Append("POLICY_CLIENT_LAST_UPD_BY")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_last_upd_dt) Then
                            .Append("POLICY_CLIENT_LAST_UPD_DT")
                            shrtFlag -= POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_CLIENT_DTL_VO_OTHER, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other = POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_CLIENT_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_cd) Then .AddWithValue("@policy_client_cd", Value.POLICY_CLIENT_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.OCCUPATION) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.occupation) Then .AddWithValue("@occupation", Value.OCCUPATION)
                If Not IsNothing(Value.POLICY_CLIENT_POSITION) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_position) Then .AddWithValue("@policy_client_position", Value.POLICY_CLIENT_POSITION)
                If Not IsNothing(Value.BUSINESS_NATURE) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.business_nature) Then .AddWithValue("@business_nature", Value.BUSINESS_NATURE)
                If Not IsNothing(Value.ID_TYPE) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_type) Then .AddWithValue("@id_type", Value.ID_TYPE)
                If Not IsNothing(Value.ID_NO) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.id_no) Then .AddWithValue("@id_no", Value.ID_NO)
                If Not IsNothing(Value.SOURCE_FUND) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.source_fund) Then .AddWithValue("@source_fund", Value.SOURCE_FUND)
                If Not IsNothing(Value.SMOKE_ST) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.smoke_st) Then .AddWithValue("@smoke_st", Value.SMOKE_ST)
                If Not IsNothing(Value.REMARKS) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.remarks) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not IsNothing(Value.POLICY_CLIENT_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_crea_by) Then .AddWithValue("@policy_client_crea_by", Value.POLICY_CLIENT_CREA_BY)
                If Year(Value.POLICY_CLIENT_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_crea_dt) Then .AddWithValue("@policy_client_crea_dt", Value.POLICY_CLIENT_CREA_DT)
                If Not IsNothing(Value.POLICY_CLIENT_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_last_upd_by) Then .AddWithValue("@policy_client_last_upd_by", Value.POLICY_CLIENT_LAST_UPD_BY)
                If Year(Value.POLICY_CLIENT_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_DTL_VO_OTHER.Enum_POLICY_CLIENT_DTL_other.policy_client_last_upd_dt) Then .AddWithValue("@policy_client_last_upd_dt", Value.POLICY_CLIENT_LAST_UPD_DT)
            End With
        End Sub
    End Class


#End Region

#Region "policy_client_attach"

    <Serializable()> _
    Public Class POLICY_CLIENT_ATTACH_VO

        Public POLICY_ATTACH_CD As String
        Public POLICY_CLIENT_CD As String
        Public POLICY_SEQ_CD As String
        Public FILENAME As String
        Public CAPTION As String
        Public POLICY_ATTACH_CREA_BY As String
        Public POLICY_ATTACH_CREA_DT As Date
        Public POLICY_ATTACH_LAST_UPD_BY As String
        Public POLICY_ATTACH_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_CLIENT_ATTACH As Short
            NONE = 0
            policy_attach_cd = 1
            policy_client_cd = 2
            policy_seq_cd = 4
            filename = 8
            caption = 16
            policy_attach_crea_by = 32
            policy_attach_crea_dt = 64
            policy_attach_last_upd_by = 128
            policy_attach_last_upd_dt = 256
        End Enum

    End Class

    Public Class POLICY_CLIENT_ATTACH_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_CLIENT_ATTACH_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_client_attach_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_CLIENT_ATTACH_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_CLIENT_ATTACH_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_client_attach_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_CLIENT_ATTACH_VO, Optional ByVal ExcludeValue As POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM POLICY_CLIENT_ATTACH " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_CLIENT_ATTACH_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH = POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.POLICY_ATTACH_CD) Then shrtFlag += POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_cd
                If Not IsNothing(.POLICY_CLIENT_CD) Then shrtFlag += POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_client_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_seq_cd
                If Not IsNothing(.FILENAME) Then shrtFlag += POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.filename
                If Not IsNothing(.CAPTION) Then shrtFlag += POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.caption
                If Not IsNothing(.POLICY_ATTACH_CREA_BY) Then shrtFlag += POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_crea_by
                If Year(.POLICY_ATTACH_CREA_DT) > 1 Then shrtFlag += POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_crea_dt
                If Not IsNothing(.POLICY_ATTACH_LAST_UPD_BY) Then shrtFlag += POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_last_upd_by
                If Year(.POLICY_ATTACH_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE POLICY_CLIENT_ATTACH SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO POLICY_CLIENT_ATTACH (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM POLICY_CLIENT_ATTACH WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_cd) Then
                            .Append("POLICY_ATTACH_CD")
                            shrtFlag -= POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_client_cd) Then
                            .Append("POLICY_CLIENT_CD")
                            shrtFlag -= POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_client_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.filename) Then
                            .Append("FILENAME")
                            shrtFlag -= POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.filename

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.caption) Then
                            .Append("CAPTION")
                            shrtFlag -= POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.caption

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_crea_by) Then
                            .Append("POLICY_ATTACH_CREA_BY")
                            shrtFlag -= POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_crea_dt) Then
                            .Append("POLICY_ATTACH_CREA_DT")
                            shrtFlag -= POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_last_upd_by) Then
                            .Append("POLICY_ATTACH_LAST_UPD_BY")
                            shrtFlag -= POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_last_upd_dt) Then
                            .Append("POLICY_ATTACH_LAST_UPD_DT")
                            shrtFlag -= POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_CLIENT_ATTACH_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH = POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_ATTACH_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_cd) Then .AddWithValue("@policy_attach_cd", Value.POLICY_ATTACH_CD)
                If Not IsNothing(Value.POLICY_CLIENT_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_client_cd) Then .AddWithValue("@policy_client_cd", Value.POLICY_CLIENT_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.FILENAME) And Not CheckBit(ExcludeValue, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.filename) Then .AddWithValue("@filename", Value.FILENAME)
                If Not IsNothing(Value.CAPTION) And Not CheckBit(ExcludeValue, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.caption) Then .AddWithValue("@caption", Value.CAPTION)
                If Not IsNothing(Value.POLICY_ATTACH_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_crea_by) Then .AddWithValue("@policy_attach_crea_by", Value.POLICY_ATTACH_CREA_BY)
                If Year(Value.POLICY_ATTACH_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_crea_dt) Then .AddWithValue("@policy_attach_crea_dt", Value.POLICY_ATTACH_CREA_DT)
                If Not IsNothing(Value.POLICY_ATTACH_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_last_upd_by) Then .AddWithValue("@policy_attach_last_upd_by", Value.POLICY_ATTACH_LAST_UPD_BY)
                If Year(Value.POLICY_ATTACH_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_ATTACH_VO.Enum_POLICY_CLIENT_ATTACH.policy_attach_last_upd_dt) Then .AddWithValue("@policy_attach_last_upd_dt", Value.POLICY_ATTACH_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "policy_client_corres"
    <Serializable()> _
    Public Class POLICY_CLIENT_CORRES_VO

        Public POLICY_CLIENT_CD As String
        Public POLICY_SEQ_CD As String
        Public CORRES_ADDRESS As String
        Public CORRES_ADDRESS2 As String
        Public CITY_CD As String
        Public COUNTRY_CD As String
        Public ZIP_CD As String
        Public CORRES_ST As String
        Public POLICY_CORRES_CREA_BY As String
        Public POLICY_CORRES_CREA_DT As Date
        Public POLICY_CORRES_LAST_UPD_BY As String
        Public POLICY_CORRES_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_CLIENT_CORRES As Short
            NONE = 0
            policy_client_cd = 1
            policy_seq_cd = 2
            corres_address = 4
            corres_address2 = 8
            city_cd = 16
            country_cd = 32
            zip_cd = 64
            corres_st = 128
            policy_corres_crea_by = 256
            policy_corres_crea_dt = 512
            policy_corres_last_upd_by = 1024
            policy_corres_last_upd_dt = 2048
        End Enum

    End Class


    Public Class POLICY_CLIENT_CORRES_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_CLIENT_CORRES_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_client_corres_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_CLIENT_CORRES_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_CLIENT_CORRES_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_client_corres_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_CLIENT_CORRES_VO, Optional ByVal ExcludeValue As POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM POLICY_CLIENT_CORRES " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_CLIENT_CORRES_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES = POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_client_cd
                Else
                    If .POLICY_CLIENT_CD <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_client_cd
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_seq_cd
                Else
                    If .POLICY_SEQ_CD <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_seq_cd
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address
                Else
                    If .CORRES_ADDRESS <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address2
                Else
                    If .CORRES_ADDRESS2 <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address2
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.city_cd
                Else
                    If .CITY_CD <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.city_cd
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.country_cd
                Else
                    If .COUNTRY_CD <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.country_cd
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.zip_cd
                Else
                    If .ZIP_CD <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.zip_cd
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_st
                Else
                    If .CORRES_ST <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_st
                End If
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_crea_by
                Else
                    If .POLICY_CORRES_CREA_BY <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_crea_by
                End If
                If Year(.POLICY_CORRES_CREA_DT) > 1 Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_crea_dt
                If (QueryType = QueryType.UpdateType Or QueryType = QueryType.InsertType) And IncludeBlanks = True Then
                    shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_last_upd_by
                Else
                    If .POLICY_CORRES_LAST_UPD_BY <> "" Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_last_upd_by
                End If
                If Year(.POLICY_CORRES_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE POLICY_CLIENT_CORRES SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO POLICY_CLIENT_CORRES (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM POLICY_CLIENT_CORRES WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_client_cd) Then
                            .Append("POLICY_CLIENT_CD")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_client_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address) Then
                            .Append("CORRES_ADDRESS")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address2) Then
                            .Append("CORRES_ADDRESS2")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address2

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.city_cd) Then
                            .Append("CITY_CD")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.city_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.country_cd) Then
                            .Append("COUNTRY_CD")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.country_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.zip_cd) Then
                            .Append("ZIP_CD")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.zip_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_st) Then
                            .Append("CORRES_ST")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_st

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_crea_by) Then
                            .Append("POLICY_CORRES_CREA_BY")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_crea_dt) Then
                            .Append("POLICY_CORRES_CREA_DT")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_last_upd_by) Then
                            .Append("POLICY_CORRES_LAST_UPD_BY")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_last_upd_dt) Then
                            .Append("POLICY_CORRES_LAST_UPD_DT")
                            shrtFlag -= POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_CLIENT_CORRES_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES = POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_CLIENT_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_client_cd) Then .AddWithValue("@policy_client_cd", Value.POLICY_CLIENT_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.CORRES_ADDRESS) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address) Then .AddWithValue("@corres_address", Value.CORRES_ADDRESS)
                If Not IsNothing(Value.CORRES_ADDRESS2) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_address2) Then .AddWithValue("@corres_address2", Value.CORRES_ADDRESS2)
                If Not IsNothing(Value.CITY_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.city_cd) Then .AddWithValue("@city_cd", Value.CITY_CD)
                If Not IsNothing(Value.COUNTRY_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.country_cd) Then .AddWithValue("@country_cd", Value.COUNTRY_CD)
                If Not IsNothing(Value.ZIP_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.zip_cd) Then .AddWithValue("@zip_cd", Value.ZIP_CD)
                If Not IsNothing(Value.CORRES_ST) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.corres_st) Then .AddWithValue("@corres_st", Value.CORRES_ST)
                If Not IsNothing(Value.POLICY_CORRES_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_crea_by) Then .AddWithValue("@policy_corres_crea_by", Value.POLICY_CORRES_CREA_BY)
                If Year(Value.POLICY_CORRES_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_crea_dt) Then .AddWithValue("@policy_corres_crea_dt", Value.POLICY_CORRES_CREA_DT)
                If Not IsNothing(Value.POLICY_CORRES_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_last_upd_by) Then .AddWithValue("@policy_corres_last_upd_by", Value.POLICY_CORRES_LAST_UPD_BY)
                If Year(Value.POLICY_CORRES_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_CORRES_VO.Enum_POLICY_CLIENT_CORRES.policy_corres_last_upd_dt) Then .AddWithValue("@policy_corres_last_upd_dt", Value.POLICY_CORRES_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "policy_client_risk"
    <Serializable()> _
    Public Class POLICY_CLIENT_RISK_VO

        Public POLICY_CLIENT_CD As String
        Public RISK_DTL_CD As String
        Public RISK_PROFILE_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_CLIENT_RISK_CREA_BY As String
        Public POLICY_CLIENT_RISK_CREA_DT As Date
        Public POLICY_CLIENT_RISK_LAST_UPD_BY As String
        Public POLICY_CLIENT_RISK_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_CLIENT_RISK As Short
            NONE = 0
            policy_client_cd = 1
            risk_dtl_cd = 2
            risk_profile_cd = 4
            policy_seq_cd = 8
            policy_client_risk_crea_by = 16
            policy_client_risk_crea_dt = 32
            policy_client_risk_last_upd_by = 64
            policy_client_risk_last_upd_dt = 128
        End Enum

    End Class

    Public Class POLICY_CLIENT_RISK_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_CLIENT_RISK_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_client_risk_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_CLIENT_RISK_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Search(ByVal Value As POLICY_CLIENT_RISK_VO, Optional ByVal ExcludeValue As POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM POLICY_CLIENT_RISK " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_CLIENT_RISK_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK = POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.POLICY_CLIENT_CD) Then shrtFlag += POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_cd
                If Not IsNothing(.RISK_DTL_CD) Then shrtFlag += POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.risk_dtl_cd
                If Not IsNothing(.RISK_PROFILE_CD) Then shrtFlag += POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.risk_profile_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_seq_cd
                If Not IsNothing(.POLICY_CLIENT_RISK_CREA_BY) Then shrtFlag += POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_crea_by
                If Year(.POLICY_CLIENT_RISK_CREA_DT) > 1 Then shrtFlag += POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_crea_dt
                If Not IsNothing(.POLICY_CLIENT_RISK_LAST_UPD_BY) Then shrtFlag += POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_last_upd_by
                If Year(.POLICY_CLIENT_RISK_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE POLICY_CLIENT_RISK SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO POLICY_CLIENT_RISK (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM POLICY_CLIENT_RISK WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_cd) Then
                            .Append("POLICY_CLIENT_CD")
                            shrtFlag -= POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.risk_dtl_cd) Then
                            .Append("RISK_DTL_CD")
                            shrtFlag -= POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.risk_dtl_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.risk_profile_cd) Then
                            .Append("RISK_PROFILE_CD")
                            shrtFlag -= POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.risk_profile_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_crea_by) Then
                            .Append("POLICY_CLIENT_RISK_CREA_BY")
                            shrtFlag -= POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_crea_dt) Then
                            .Append("POLICY_CLIENT_RISK_CREA_DT")
                            shrtFlag -= POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_last_upd_by) Then
                            .Append("POLICY_CLIENT_RISK_LAST_UPD_BY")
                            shrtFlag -= POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_last_upd_dt) Then
                            .Append("POLICY_CLIENT_RISK_LAST_UPD_DT")
                            shrtFlag -= POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_CLIENT_RISK_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK = POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_CLIENT_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_cd) Then .AddWithValue("@policy_client_cd", Value.POLICY_CLIENT_CD)
                If Not IsNothing(Value.RISK_DTL_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.risk_dtl_cd) Then .AddWithValue("@risk_dtl_cd", Value.RISK_DTL_CD)
                If Not IsNothing(Value.RISK_PROFILE_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.risk_profile_cd) Then .AddWithValue("@risk_profile_cd", Value.RISK_PROFILE_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.POLICY_CLIENT_RISK_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_crea_by) Then .AddWithValue("@policy_client_risk_crea_by", Value.POLICY_CLIENT_RISK_CREA_BY)
                If Year(Value.POLICY_CLIENT_RISK_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_crea_dt) Then .AddWithValue("@policy_client_risk_crea_dt", Value.POLICY_CLIENT_RISK_CREA_DT)
                If Not IsNothing(Value.POLICY_CLIENT_RISK_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_last_upd_by) Then .AddWithValue("@policy_client_risk_last_upd_by", Value.POLICY_CLIENT_RISK_LAST_UPD_BY)
                If Year(Value.POLICY_CLIENT_RISK_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CLIENT_RISK_VO.Enum_POLICY_CLIENT_RISK.policy_client_risk_last_upd_dt) Then .AddWithValue("@policy_client_risk_last_upd_dt", Value.POLICY_CLIENT_RISK_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "policy_trustees_dtl"

    <Serializable()> _
    Public Class POLICY_TRUSTEES_DTL_VO

        Public POLICY_TRUSTEES_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_TRUSTEES_LAST_NAME As String
        Public POLICY_TRUSTEES_FIRST_NAME As String
        Public POLICY_TRUSTEES_MIDDLE_NAME As String
        Public RELATIONSHIP As String
        Public GENDER As String
        Public BIRTHDAY As Date
        Public POLICY_TRUSTEES_ADDRESS As String
        Public POLICY_TRUSTEES_ADDRESS2 As String
        Public CITY_CD As String
        Public COUNTRY_CD As String
        Public ZIP_CD As String
        Public TEL_NO As String
        Public MOBILE_NO As String
        Public OCCUPATION As String
        Public ID_TYPE As String
        Public ID_NO As String
        Public RANKING_CD As String
        Public POLICY_TRUSTEES_CREA_BY As String
        Public POLICY_TRUSTEES_CREA_DT As Date
        Public POLICY_TRUSTEES_LAST_UPD_BY As String
        Public POLICY_TRUSTEES_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_TRUSTEES_DTL As Integer
            NONE = 0
            policy_trustees_cd = 1
            policy_seq_cd = 2
            policy_trustees_last_name = 4
            policy_trustees_first_name = 8
            policy_trustees_middle_name = 16
            relationship = 32
            gender = 64
            birthday = 128
            policy_trustees_address = 256
            policy_trustees_address2 = 512
            city_cd = 1024
            country_cd = 2048
            zip_cd = 4096
            tel_no = 8192
            mobile_no = 16384
            occupation = 32768
            id_type = 65536
            id_no = 131072
            ranking_cd = 262144
            policy_trustees_crea_by = 524288
            policy_trustees_crea_dt = 1048576
            policy_trustees_last_upd_by = 2097152
            policy_trustees_last_upd_dt = 4194304
        End Enum

    End Class

    Public Class POLICY_TRUSTEES_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_TRUSTEES_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_trustees_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_TRUSTEES_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_TRUSTEES_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_trustees_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_TRUSTEES_DTL_VO, Optional ByVal ExcludeValue As POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM POLICY_TRUSTEES_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_TRUSTEES_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL = POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not IsNothing(.POLICY_TRUSTEES_CD) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_seq_cd
                If Not IsNothing(.POLICY_TRUSTEES_LAST_NAME) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_name
                If Not IsNothing(.POLICY_TRUSTEES_FIRST_NAME) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_first_name
                If Not IsNothing(.POLICY_TRUSTEES_MIDDLE_NAME) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_middle_name
                If Not IsNothing(.RELATIONSHIP) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.relationship
                If Not IsNothing(.GENDER) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.gender
                If Year(.BIRTHDAY) > 1 Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.birthday
                If Not IsNothing(.POLICY_TRUSTEES_ADDRESS) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_address
                If Not IsNothing(.POLICY_TRUSTEES_ADDRESS2) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_address2
                If Not IsNothing(.CITY_CD) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.city_cd
                If Not IsNothing(.COUNTRY_CD) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.country_cd
                If Not IsNothing(.ZIP_CD) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.zip_cd
                If Not IsNothing(.TEL_NO) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.tel_no
                If Not IsNothing(.MOBILE_NO) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.mobile_no
                If Not IsNothing(.OCCUPATION) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.occupation
                If Not IsNothing(.ID_TYPE) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.id_type
                If Not IsNothing(.ID_NO) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.id_no
                If Not IsNothing(.RANKING_CD) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.ranking_cd
                If Not IsNothing(.POLICY_TRUSTEES_CREA_BY) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_crea_by
                If Year(.POLICY_TRUSTEES_CREA_DT) > 1 Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_crea_dt
                If Not IsNothing(.POLICY_TRUSTEES_LAST_UPD_BY) Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_upd_by
                If Year(.POLICY_TRUSTEES_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE POLICY_TRUSTEES_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO POLICY_TRUSTEES_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM POLICY_TRUSTEES_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_cd) Then
                            .Append("POLICY_TRUSTEES_CD")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_cd

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_name) Then
                            .Append("POLICY_TRUSTEES_LAST_NAME")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_name

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_first_name) Then
                            .Append("POLICY_TRUSTEES_FIRST_NAME")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_first_name

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_middle_name) Then
                            .Append("POLICY_TRUSTEES_MIDDLE_NAME")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_middle_name

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.relationship) Then
                            .Append("RELATIONSHIP")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.relationship

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.gender) Then
                            .Append("GENDER")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.gender

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.birthday) Then
                            .Append("BIRTHDAY")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.birthday

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_address) Then
                            .Append("POLICY_TRUSTEES_ADDRESS")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_address

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_address2) Then
                            .Append("POLICY_TRUSTEES_ADDRESS2")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_address2

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.city_cd) Then
                            .Append("CITY_CD")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.city_cd

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.country_cd) Then
                            .Append("COUNTRY_CD")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.country_cd

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.zip_cd) Then
                            .Append("ZIP_CD")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.zip_cd

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.tel_no) Then
                            .Append("TEL_NO")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.tel_no

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.mobile_no) Then
                            .Append("MOBILE_NO")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.mobile_no

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.occupation) Then
                            .Append("OCCUPATION")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.occupation

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.id_type) Then
                            .Append("ID_TYPE")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.id_type

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.id_no) Then
                            .Append("ID_NO")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.id_no

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.ranking_cd) Then
                            .Append("RANKING_CD")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.ranking_cd

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_crea_by) Then
                            .Append("POLICY_TRUSTEES_CREA_BY")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_crea_dt) Then
                            .Append("POLICY_TRUSTEES_CREA_DT")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_upd_by) Then
                            .Append("POLICY_TRUSTEES_LAST_UPD_BY")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_upd_dt) Then
                            .Append("POLICY_TRUSTEES_LAST_UPD_DT")
                            shrtFlag -= POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_TRUSTEES_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL = POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_TRUSTEES_CD) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_cd) Then .AddWithValue("@policy_trustees_cd", Value.POLICY_TRUSTEES_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.POLICY_TRUSTEES_LAST_NAME) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_name) Then .AddWithValue("@policy_trustees_last_name", Value.POLICY_TRUSTEES_LAST_NAME)
                If Not IsNothing(Value.POLICY_TRUSTEES_FIRST_NAME) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_first_name) Then .AddWithValue("@policy_trustees_first_name", Value.POLICY_TRUSTEES_FIRST_NAME)
                If Not IsNothing(Value.POLICY_TRUSTEES_MIDDLE_NAME) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_middle_name) Then .AddWithValue("@policy_trustees_middle_name", Value.POLICY_TRUSTEES_MIDDLE_NAME)
                If Not IsNothing(Value.RELATIONSHIP) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.relationship) Then .AddWithValue("@relationship", Value.RELATIONSHIP)
                If Not IsNothing(Value.GENDER) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.gender) Then .AddWithValue("@gender", Value.GENDER)
                If Year(Value.BIRTHDAY) > 1 And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.birthday) Then .AddWithValue("@birthday", Value.BIRTHDAY)
                If Not IsNothing(Value.POLICY_TRUSTEES_ADDRESS) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_address) Then .AddWithValue("@policy_trustees_address", Value.POLICY_TRUSTEES_ADDRESS)
                If Not IsNothing(Value.POLICY_TRUSTEES_ADDRESS2) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_address2) Then .AddWithValue("@policy_trustees_address2", Value.POLICY_TRUSTEES_ADDRESS2)
                If Not IsNothing(Value.CITY_CD) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.city_cd) Then .AddWithValue("@city_cd", Value.CITY_CD)
                If Not IsNothing(Value.COUNTRY_CD) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.country_cd) Then .AddWithValue("@country_cd", Value.COUNTRY_CD)
                If Not IsNothing(Value.ZIP_CD) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.zip_cd) Then .AddWithValue("@zip_cd", Value.ZIP_CD)
                If Not IsNothing(Value.TEL_NO) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.tel_no) Then .AddWithValue("@tel_no", Value.TEL_NO)
                If Not IsNothing(Value.MOBILE_NO) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.mobile_no) Then .AddWithValue("@mobile_no", Value.MOBILE_NO)
                If Not IsNothing(Value.OCCUPATION) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.occupation) Then .AddWithValue("@occupation", Value.OCCUPATION)
                If Not IsNothing(Value.ID_TYPE) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.id_type) Then .AddWithValue("@id_type", Value.ID_TYPE)
                If Not IsNothing(Value.ID_NO) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.id_no) Then .AddWithValue("@id_no", Value.ID_NO)
                If Not IsNothing(Value.RANKING_CD) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.ranking_cd) Then .AddWithValue("@ranking_cd", Value.RANKING_CD)
                If Not IsNothing(Value.POLICY_TRUSTEES_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_crea_by) Then .AddWithValue("@policy_trustees_crea_by", Value.POLICY_TRUSTEES_CREA_BY)
                If Year(Value.POLICY_TRUSTEES_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_crea_dt) Then .AddWithValue("@policy_trustees_crea_dt", Value.POLICY_TRUSTEES_CREA_DT)
                If Not IsNothing(Value.POLICY_TRUSTEES_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_upd_by) Then .AddWithValue("@policy_trustees_last_upd_by", Value.POLICY_TRUSTEES_LAST_UPD_BY)
                If Year(Value.POLICY_TRUSTEES_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_TRUSTEES_DTL_VO.Enum_POLICY_TRUSTEES_DTL.policy_trustees_last_upd_dt) Then .AddWithValue("@policy_trustees_last_upd_dt", Value.POLICY_TRUSTEES_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "policy_bene_dtl"

    <Serializable()> _
    Public Class POLICY_BENE_DTL_VO

        Public POLICY_BENE_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_BENE_LAST_NAME As String
        Public POLICY_BENE_FIRST_NAME As String
        Public POLICY_BENE_MIDDLE_NAME As String
        Public RELATIONSHIP As String
        Public GENDER As String
        Public BIRTHDAY As Date
        Public POLICY_BENE_ADDRESS As String
        Public POLICY_BENE_ADDRESS2 As String
        Public CITY_CD As String
        Public COUNTRY_CD As String
        Public ZIP_CD As String
        Public TEL_NO As String
        Public MOBILE_NO As String
        Public OCCUPATION As String
        Public ID_TYPE As String
        Public ID_NO As String
        Public RANKING_CD As String
        Public SHARE As Double = -1
        Public POLICY_BENE_CREA_BY As String
        Public POLICY_BENE_CREA_DT As Date
        Public POLICY_BENE_LAST_UPD_BY As String
        Public POLICY_BENE_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_BENE_DTL As Integer
            NONE = 0
            policy_bene_cd = 1
            policy_seq_cd = 2
            policy_bene_last_name = 4
            policy_bene_first_name = 8
            policy_bene_middle_name = 16
            relationship = 32
            gender = 64
            birthday = 128
            policy_bene_address = 256
            policy_bene_address2 = 512
            city_cd = 1024
            country_cd = 2048
            zip_cd = 4096
            tel_no = 8192
            mobile_no = 16384
            occupation = 32768
            id_type = 65536
            id_no = 131072
            ranking_cd = 262144
            share = 524288
            policy_bene_crea_by = 1048576
            policy_bene_crea_dt = 2097152
            policy_bene_last_upd_by = 4194304
            policy_bene_last_upd_dt = 8388608
        End Enum

    End Class

    Public Class POLICY_BENE_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_BENE_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_bene_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_BENE_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_BENE_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_bene_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_BENE_DTL_VO, Optional ByVal ExcludeValue As POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM POLICY_BENE_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_BENE_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL = POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not IsNothing(.POLICY_BENE_CD) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_seq_cd
                If Not IsNothing(.POLICY_BENE_LAST_NAME) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_name
                If Not IsNothing(.POLICY_BENE_FIRST_NAME) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_first_name
                If Not IsNothing(.POLICY_BENE_MIDDLE_NAME) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_middle_name
                If Not IsNothing(.RELATIONSHIP) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.relationship
                If Not IsNothing(.GENDER) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.gender
                If Year(.BIRTHDAY) > 1 Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.birthday
                If Not IsNothing(.POLICY_BENE_ADDRESS) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_address
                If Not IsNothing(.POLICY_BENE_ADDRESS2) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_address2
                If Not IsNothing(.CITY_CD) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.city_cd
                If Not IsNothing(.COUNTRY_CD) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.country_cd
                If Not IsNothing(.ZIP_CD) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.zip_cd
                If Not IsNothing(.TEL_NO) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.tel_no
                If Not IsNothing(.MOBILE_NO) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.mobile_no
                If Not IsNothing(.OCCUPATION) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.occupation
                If Not IsNothing(.ID_TYPE) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.id_type
                If Not IsNothing(.ID_NO) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.id_no
                If Not IsNothing(.RANKING_CD) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.ranking_cd
                If .SHARE >= 0 Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.share
                If Not IsNothing(.POLICY_BENE_CREA_BY) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_crea_by
                If Year(.POLICY_BENE_CREA_DT) > 1 Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_crea_dt
                If Not IsNothing(.POLICY_BENE_LAST_UPD_BY) Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_upd_by
                If Year(.POLICY_BENE_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE POLICY_BENE_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO POLICY_BENE_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM POLICY_BENE_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_cd) Then
                            .Append("POLICY_BENE_CD")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_cd

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_name) Then
                            .Append("POLICY_BENE_LAST_NAME")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_name

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_first_name) Then
                            .Append("POLICY_BENE_FIRST_NAME")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_first_name

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_middle_name) Then
                            .Append("POLICY_BENE_MIDDLE_NAME")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_middle_name

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.relationship) Then
                            .Append("RELATIONSHIP")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.relationship

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.gender) Then
                            .Append("GENDER")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.gender

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.birthday) Then
                            .Append("BIRTHDAY")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.birthday

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_address) Then
                            .Append("POLICY_BENE_ADDRESS")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_address

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_address2) Then
                            .Append("POLICY_BENE_ADDRESS2")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_address2

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.city_cd) Then
                            .Append("CITY_CD")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.city_cd

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.country_cd) Then
                            .Append("COUNTRY_CD")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.country_cd

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.zip_cd) Then
                            .Append("ZIP_CD")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.zip_cd

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.tel_no) Then
                            .Append("TEL_NO")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.tel_no

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.mobile_no) Then
                            .Append("MOBILE_NO")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.mobile_no

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.occupation) Then
                            .Append("OCCUPATION")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.occupation

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.id_type) Then
                            .Append("ID_TYPE")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.id_type

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.id_no) Then
                            .Append("ID_NO")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.id_no

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.ranking_cd) Then
                            .Append("RANKING_CD")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.ranking_cd

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.share) Then
                            .Append("SHARE")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.share

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_crea_by) Then
                            .Append("POLICY_BENE_CREA_BY")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_crea_dt) Then
                            .Append("POLICY_BENE_CREA_DT")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_upd_by) Then
                            .Append("POLICY_BENE_LAST_UPD_BY")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_upd_dt) Then
                            .Append("POLICY_BENE_LAST_UPD_DT")
                            shrtFlag -= POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_BENE_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL = POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_BENE_CD) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_cd) Then .AddWithValue("@policy_bene_cd", Value.POLICY_BENE_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.POLICY_BENE_LAST_NAME) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_name) Then .AddWithValue("@policy_bene_last_name", Value.POLICY_BENE_LAST_NAME)
                If Not IsNothing(Value.POLICY_BENE_FIRST_NAME) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_first_name) Then .AddWithValue("@policy_bene_first_name", Value.POLICY_BENE_FIRST_NAME)
                If Not IsNothing(Value.POLICY_BENE_MIDDLE_NAME) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_middle_name) Then .AddWithValue("@policy_bene_middle_name", Value.POLICY_BENE_MIDDLE_NAME)
                If Not IsNothing(Value.RELATIONSHIP) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.relationship) Then .AddWithValue("@relationship", Value.RELATIONSHIP)
                If Not IsNothing(Value.GENDER) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.gender) Then .AddWithValue("@gender", Value.GENDER)
                If Year(Value.BIRTHDAY) > 1 And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.birthday) Then .AddWithValue("@birthday", Value.BIRTHDAY)
                If Not IsNothing(Value.POLICY_BENE_ADDRESS) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_address) Then .AddWithValue("@policy_bene_address", Value.POLICY_BENE_ADDRESS)
                If Not IsNothing(Value.POLICY_BENE_ADDRESS2) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_address2) Then .AddWithValue("@policy_bene_address2", Value.POLICY_BENE_ADDRESS2)
                If Not IsNothing(Value.CITY_CD) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.city_cd) Then .AddWithValue("@city_cd", Value.CITY_CD)
                If Not IsNothing(Value.COUNTRY_CD) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.country_cd) Then .AddWithValue("@country_cd", Value.COUNTRY_CD)
                If Not IsNothing(Value.ZIP_CD) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.zip_cd) Then .AddWithValue("@zip_cd", Value.ZIP_CD)
                If Not IsNothing(Value.TEL_NO) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.tel_no) Then .AddWithValue("@tel_no", Value.TEL_NO)
                If Not IsNothing(Value.MOBILE_NO) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.mobile_no) Then .AddWithValue("@mobile_no", Value.MOBILE_NO)
                If Not IsNothing(Value.OCCUPATION) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.occupation) Then .AddWithValue("@occupation", Value.OCCUPATION)
                If Not IsNothing(Value.ID_TYPE) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.id_type) Then .AddWithValue("@id_type", Value.ID_TYPE)
                If Not IsNothing(Value.ID_NO) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.id_no) Then .AddWithValue("@id_no", Value.ID_NO)
                If Not IsNothing(Value.RANKING_CD) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.ranking_cd) Then .AddWithValue("@ranking_cd", Value.RANKING_CD)
                If Value.SHARE >= 0 And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.share) Then .AddWithValue("@share", Value.SHARE)
                If Not IsNothing(Value.POLICY_BENE_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_crea_by) Then .AddWithValue("@policy_bene_crea_by", Value.POLICY_BENE_CREA_BY)
                If Year(Value.POLICY_BENE_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_crea_dt) Then .AddWithValue("@policy_bene_crea_dt", Value.POLICY_BENE_CREA_DT)
                If Not IsNothing(Value.POLICY_BENE_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_upd_by) Then .AddWithValue("@policy_bene_last_upd_by", Value.POLICY_BENE_LAST_UPD_BY)
                If Year(Value.POLICY_BENE_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_BENE_DTL_VO.Enum_POLICY_BENE_DTL.policy_bene_last_upd_dt) Then .AddWithValue("@policy_bene_last_upd_dt", Value.POLICY_BENE_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "policy_prem_rider_dtl"

    <Serializable()> _
    Public Class POLICY_PREM_RIDER_DTL_VO

        Public PREM_RIDER_CD As String
        Public POLICY_PREM_RIDER_START_DT As Date
        Public POLICY_PREM_RIDER_START_DT_END As Date
        Public POLICY_SEQ_CD As String
        Public POLICY_PREM_RIDER_END_DT As Date
        Public POLICY_PREM_RIDER_END_DT_END As Date
        Public BENEFITS As Double = -1
        Public PREMIUM_AMT As Double = -1
        Public REMARKS As String
        Public POLICY_PREM_RIDER_CREA_BY As String
        Public POLICY_PREM_RIDER_CREA_DT As Date
        Public POLICY_PREM_RIDER_CREA_DT_END As Date
        Public POLICY_PREM_RIDER_LAST_UPD_BY As String
        Public POLICY_PREM_RIDER_LAST_UPD_DT As Date
        Public POLICY_PREM_RIDER_LAST_UPD_DT_END As Date

        Public Enum Enum_policy_prem_rider_dtl As Integer
            NONE = 0
            prem_rider_cd = 1
            policy_prem_rider_start_dt = 2
            policy_prem_rider_start_dt_END = 4
            policy_seq_cd = 8
            policy_prem_rider_end_dt = 16
            policy_prem_rider_end_dt_END = 32
            benefits = 64
            premium_amt = 128
            remarks = 256
            policy_prem_rider_crea_by = 512
            policy_prem_rider_crea_dt = 1024
            policy_prem_rider_crea_dt_END = 2048
            policy_prem_rider_last_upd_by = 4096
            policy_prem_rider_last_upd_dt = 8192
            policy_prem_rider_last_upd_dt_END = 16384
        End Enum

    End Class

    Public Class POLICY_PREM_RIDER_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As policy_prem_rider_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_prem_rider_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As policy_prem_rider_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As policy_prem_rider_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_prem_rider_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As policy_prem_rider_dtl_VO, Optional ByVal ExcludeValue As policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM policy_prem_rider_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_PREM_RIDER_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl = POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not isnothing(.PREM_RIDER_CD) Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.PREM_RIDER_CD
                If Year(.POLICY_PREM_RIDER_START_DT) > 1 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_START_DT
                If Year(.POLICY_PREM_RIDER_START_DT_END) > 1 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_START_DT_END
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_SEQ_CD
                If Year(.POLICY_PREM_RIDER_END_DT) > 1 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_END_DT
                If Year(.POLICY_PREM_RIDER_END_DT_END) > 1 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_END_DT_END
                If .BENEFITS >= 0 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.BENEFITS
                If .PREMIUM_AMT >= 0 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.PREMIUM_AMT
                If Not isnothing(.REMARKS) Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.REMARKS
                If Not isnothing(.POLICY_PREM_RIDER_CREA_BY) Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_BY
                If Year(.POLICY_PREM_RIDER_CREA_DT) > 1 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_DT
                If Year(.POLICY_PREM_RIDER_CREA_DT_END) > 1 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_DT_END
                If Not isnothing(.POLICY_PREM_RIDER_LAST_UPD_BY) Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_BY
                If Year(.POLICY_PREM_RIDER_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_DT
                If Year(.POLICY_PREM_RIDER_LAST_UPD_DT_END) > 1 Then shrtFlag += POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_DT_END
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE policy_prem_rider_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO policy_prem_rider_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM policy_prem_rider_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.PREM_RIDER_CD) Then
                            .Append("PREM_RIDER_CD")
                            shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.PREM_RIDER_CD

                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_START_DT) Then
                            If CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_START_DT_END) Then
                                shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_START_DT
                                shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_START_DT_END
                                .Append(" POLICY_PREM_RIDER_START_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_END_DT) Then
                            If CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_END_DT_END) Then
                                shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_END_DT
                                shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_END_DT_END
                                .Append(" POLICY_PREM_RIDER_END_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.BENEFITS) Then
                            .Append("BENEFITS")
                            shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.BENEFITS

                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.PREMIUM_AMT) Then
                            .Append("PREMIUM_AMT")
                            shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.PREMIUM_AMT

                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.REMARKS) Then
                            .Append("REMARKS")
                            shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.REMARKS

                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_BY) Then
                            .Append("POLICY_PREM_RIDER_CREA_BY")
                            shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_BY

                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_DT) Then
                            If CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_DT_END) Then
                                shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_DT
                                shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_DT_END
                                .Append(" POLICY_PREM_RIDER_CREA_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_BY) Then
                            .Append("POLICY_PREM_RIDER_LAST_UPD_BY")
                            shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_BY

                        ElseIf CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_DT) Then
                            If CheckBit(shrtFlag, POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_DT_END) Then
                                shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_DT
                                shrtFlag -= POLICY_PREM_RIDER_DTL_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_DT_END
                                .Append(" POLICY_PREM_RIDER_LAST_UPD_DT between ? And ? ")
                                QueryType = 4
                            End If
                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As policy_prem_rider_dtl_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl = policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.None)
            With Command.Parameters
                If Not isnothing(Value.PREM_RIDER_CD) And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.PREM_RIDER_CD) Then .AddWithValue("@prem_rider_cd", Value.PREM_RIDER_CD)
                If Year(Value.POLICY_PREM_RIDER_START_DT) > 1 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_START_DT) Then .AddWithValue("@policy_prem_rider_start_dt", Value.POLICY_PREM_RIDER_START_DT)
                If Year(Value.POLICY_PREM_RIDER_START_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_START_DT_END) Then .AddWithValue("@policy_prem_rider_start_dt_END", Value.POLICY_PREM_RIDER_START_DT_END)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Year(Value.POLICY_PREM_RIDER_END_DT) > 1 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_END_DT) Then .AddWithValue("@policy_prem_rider_end_dt", Value.POLICY_PREM_RIDER_END_DT)
                If Year(Value.POLICY_PREM_RIDER_END_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_END_DT_END) Then .AddWithValue("@policy_prem_rider_end_dt_END", Value.POLICY_PREM_RIDER_END_DT_END)
                If Value.BENEFITS >= 0 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.BENEFITS) Then .AddWithValue("@benefits", Value.BENEFITS)
                If Value.PREMIUM_AMT >= 0 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.PREMIUM_AMT) Then .AddWithValue("@premium_amt", Value.PREMIUM_AMT)
                If Not isnothing(Value.REMARKS) And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.REMARKS) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not isnothing(Value.POLICY_PREM_RIDER_CREA_BY) And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_BY) Then .AddWithValue("@policy_prem_rider_crea_by", Value.POLICY_PREM_RIDER_CREA_BY)
                If Year(Value.POLICY_PREM_RIDER_CREA_DT) > 1 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_DT) Then .AddWithValue("@policy_prem_rider_crea_dt", Value.POLICY_PREM_RIDER_CREA_DT)
                If Year(Value.POLICY_PREM_RIDER_CREA_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_CREA_DT_END) Then .AddWithValue("@policy_prem_rider_crea_dt_END", Value.POLICY_PREM_RIDER_CREA_DT_END)
                If Not isnothing(Value.POLICY_PREM_RIDER_LAST_UPD_BY) And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_BY) Then .AddWithValue("@policy_prem_rider_last_upd_by", Value.POLICY_PREM_RIDER_LAST_UPD_BY)
                If Year(Value.POLICY_PREM_RIDER_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_DT) Then .AddWithValue("@policy_prem_rider_last_upd_dt", Value.POLICY_PREM_RIDER_LAST_UPD_DT)
                If Year(Value.POLICY_PREM_RIDER_LAST_UPD_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl.POLICY_PREM_RIDER_LAST_UPD_DT_END) Then .AddWithValue("@policy_prem_rider_last_upd_dt_END", Value.POLICY_PREM_RIDER_LAST_UPD_DT_END)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As policy_prem_rider_dtl_VO, Optional ByVal ExcludeValue As policy_prem_rider_dtl_VO.Enum_policy_prem_rider_dtl = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM policy_prem_rider_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "policy_fund_dtl"

    <Serializable()> _
    Public Class POLICY_FUND_DTL_VO

        Public FUND_CD As String
        Public PRDT_CD As String
        Public POLICY_SEQ_CD As String
        Public ALLOCATION As Double = -1
        Public POLICY_FUND_CREA_BY As String
        Public POLICY_FUND_CREA_DT As Date
        Public POLICY_FUND_CREA_DT_END As Date
        Public POLICY_FUND_LAST_UPD_BY As String
        Public POLICY_FUND_LAST_UPD_DT As Date
        Public POLICY_FUND_LAST_UPD_DT_END As Date

        Public Enum Enum_POLICY_FUND_DTL As Short
            NONE = 0
            fund_cd = 1
            prdt_cd = 2
            policy_seq_cd = 4
            allocation = 8
            policy_fund_crea_by = 16
            policy_fund_crea_dt = 32
            policy_fund_crea_dt_END = 64
            policy_fund_last_upd_by = 128
            policy_fund_last_upd_dt = 256
            policy_fund_last_upd_dt_END = 512
        End Enum

    End Class

    Public Class POLICY_FUND_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As policy_fund_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_fund_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As policy_fund_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As policy_fund_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_fund_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As policy_fund_dtl_VO, Optional ByVal ExcludeValue As policy_fund_dtl_VO.Enum_policy_fund_dtl = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM policy_fund_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)

                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_FUND_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_FUND_DTL_VO.Enum_policy_fund_dtl = POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.FUND_CD) Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.FUND_CD
                If Not isnothing(.PRDT_CD) Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.PRDT_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_SEQ_CD
                If .ALLOCATION >= 0 Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.ALLOCATION
                If Not isnothing(.POLICY_FUND_CREA_BY) Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_BY
                If Year(.POLICY_FUND_CREA_DT) > 1 Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_DT
                If Year(.POLICY_FUND_CREA_DT_END) > 1 Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_DT_END
                If Not isnothing(.POLICY_FUND_LAST_UPD_BY) Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_BY
                If Year(.POLICY_FUND_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_DT
                If Year(.POLICY_FUND_LAST_UPD_DT_END) > 1 Then shrtFlag += POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_DT_END
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE policy_fund_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO policy_fund_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM policy_fund_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.FUND_CD) Then
                            .Append("FUND_CD")
                            shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.FUND_CD

                        ElseIf CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.PRDT_CD) Then
                            .Append("PRDT_CD")
                            shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.PRDT_CD

                        ElseIf CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.ALLOCATION) Then
                            .Append("ALLOCATION")
                            shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.ALLOCATION

                        ElseIf CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_BY) Then
                            .Append("POLICY_FUND_CREA_BY")
                            shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_BY

                        ElseIf CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_DT) Then
                            If CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_DT_END) Then
                                shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_DT
                                shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_DT_END
                                .Append(" POLICY_FUND_CREA_DT between ? And ? ")
                                QueryType = 4
                            End If
                        ElseIf CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_BY) Then
                            .Append("POLICY_FUND_LAST_UPD_BY")
                            shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_BY

                        ElseIf CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_DT) Then
                            If CheckBit(shrtFlag, POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_DT_END) Then
                                shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_DT
                                shrtFlag -= POLICY_FUND_DTL_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_DT_END
                                .Append(" POLICY_FUND_LAST_UPD_DT between ? And ? ")
                                QueryType = 4
                            End If
                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            '.Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As policy_fund_dtl_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As policy_fund_dtl_VO.Enum_policy_fund_dtl = policy_fund_dtl_VO.Enum_policy_fund_dtl.None)
            With Command.Parameters
                If Not isnothing(Value.FUND_CD) And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.FUND_CD) Then .AddWithValue("@fund_cd", Value.FUND_CD)
                If Not isnothing(Value.PRDT_CD) And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.PRDT_CD) Then .AddWithValue("@prdt_cd", Value.PRDT_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Value.ALLOCATION >= 0 And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.ALLOCATION) Then .AddWithValue("@allocation", Value.ALLOCATION)
                If Not isnothing(Value.POLICY_FUND_CREA_BY) And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_BY) Then .AddWithValue("@policy_fund_crea_by", Value.POLICY_FUND_CREA_BY)
                If Year(Value.POLICY_FUND_CREA_DT) > 1 And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_DT) Then .AddWithValue("@policy_fund_crea_dt", Value.POLICY_FUND_CREA_DT)
                If Year(Value.POLICY_FUND_CREA_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.POLICY_FUND_CREA_DT_END) Then .AddWithValue("@policy_fund_crea_dt_END", Value.POLICY_FUND_CREA_DT_END)
                If Not isnothing(Value.POLICY_FUND_LAST_UPD_BY) And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_BY) Then .AddWithValue("@policy_fund_last_upd_by", Value.POLICY_FUND_LAST_UPD_BY)
                If Year(Value.POLICY_FUND_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_DT) Then .AddWithValue("@policy_fund_last_upd_dt", Value.POLICY_FUND_LAST_UPD_DT)
                If Year(Value.POLICY_FUND_LAST_UPD_DT_END) > 1 And Not CheckBit(ExcludeValue, policy_fund_dtl_VO.Enum_policy_fund_dtl.POLICY_FUND_LAST_UPD_DT_END) Then .AddWithValue("@policy_fund_last_upd_dt_END", Value.POLICY_FUND_LAST_UPD_DT_END)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As policy_fund_dtl_VO, Optional ByVal ExcludeValue As policy_fund_dtl_VO.Enum_policy_fund_dtl = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM policy_fund_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "policy_adv_dtl"

    <Serializable()> _
    Public Class POLICY_ADV_DTL_VO

        Public ADVISOR_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_ADV_START_DT As Date
        Public POLICY_ADV_END_DT As Date
        Public POLICY_ADV_REMARKS As String
        Public POLICY_ADV_CREA_BY As String
        Public POLICY_ADV_CREA_DT As Date
        Public POLICY_ADV_LAST_UPD_BY As String
        Public POLICY_ADV_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_ADV_DTL As Short
            NONE = 0
            advisor_cd = 1
            policy_seq_cd = 2
            policy_adv_start_dt = 4
            policy_adv_end_dt = 8
            policy_adv_remarks = 16
            policy_adv_crea_by = 32
            policy_adv_crea_dt = 64
            policy_adv_last_upd_by = 128
            policy_adv_last_upd_dt = 256
        End Enum

    End Class

    Public Class POLICY_ADV_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_ADV_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_adv_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_ADV_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_ADV_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_adv_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_ADV_DTL_VO, Optional ByVal ExcludeValue As POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM policy_adv_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_ADV_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL = POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.ADVISOR_CD) Then shrtFlag += POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.advisor_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_seq_cd
                If Year(.POLICY_ADV_START_DT) > 1 Then shrtFlag += POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_start_dt
                If Year(.POLICY_ADV_END_DT) > 1 Then shrtFlag += POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_end_dt
                If Not IsNothing(.POLICY_ADV_REMARKS) Then shrtFlag += POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_remarks
                If Not IsNothing(.POLICY_ADV_CREA_BY) Then shrtFlag += POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_crea_by
                If Year(.POLICY_ADV_CREA_DT) > 1 Then shrtFlag += POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_crea_dt
                If Not IsNothing(.POLICY_ADV_LAST_UPD_BY) Then shrtFlag += POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_last_upd_by
                If Year(.POLICY_ADV_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE policy_adv_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO policy_adv_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM policy_adv_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.advisor_cd) Then
                            .Append("ADVISOR_CD")
                            shrtFlag -= POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.advisor_cd

                        ElseIf CheckBit(shrtFlag, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_start_dt) Then
                            .Append("POLICY_ADV_START_DT")
                            shrtFlag -= POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_start_dt

                        ElseIf CheckBit(shrtFlag, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_end_dt) Then
                            .Append("POLICY_ADV_END_DT")
                            shrtFlag -= POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_end_dt

                        ElseIf CheckBit(shrtFlag, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_remarks) Then
                            .Append("POLICY_ADV_REMARKS")
                            shrtFlag -= POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_remarks

                        ElseIf CheckBit(shrtFlag, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_crea_by) Then
                            .Append("POLICY_ADV_CREA_BY")
                            shrtFlag -= POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_crea_dt) Then
                            .Append("POLICY_ADV_CREA_DT")
                            shrtFlag -= POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_last_upd_by) Then
                            .Append("POLICY_ADV_LAST_UPD_BY")
                            shrtFlag -= POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_last_upd_dt) Then
                            .Append("POLICY_ADV_LAST_UPD_DT")
                            shrtFlag -= POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_ADV_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL = POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.advisor_cd) Then .AddWithValue("@advisor_cd", Value.ADVISOR_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Year(Value.POLICY_ADV_START_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_start_dt) Then .AddWithValue("@policy_adv_start_dt", Value.POLICY_ADV_START_DT)
                If Year(Value.POLICY_ADV_END_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_end_dt) Then .AddWithValue("@policy_adv_end_dt", Value.POLICY_ADV_END_DT)
                If Not IsNothing(Value.POLICY_ADV_REMARKS) And Not CheckBit(ExcludeValue, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_remarks) Then .AddWithValue("@policy_adv_remarks", Value.POLICY_ADV_REMARKS)
                If Not IsNothing(Value.POLICY_ADV_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_crea_by) Then .AddWithValue("@policy_adv_crea_by", Value.POLICY_ADV_CREA_BY)
                If Year(Value.POLICY_ADV_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_crea_dt) Then .AddWithValue("@policy_adv_crea_dt", Value.POLICY_ADV_CREA_DT)
                If Not IsNothing(Value.POLICY_ADV_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_last_upd_by) Then .AddWithValue("@policy_adv_last_upd_by", Value.POLICY_ADV_LAST_UPD_BY)
                If Year(Value.POLICY_ADV_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_ADV_DTL_VO.Enum_POLICY_ADV_DTL.policy_adv_last_upd_dt) Then .AddWithValue("@policy_adv_last_upd_dt", Value.POLICY_ADV_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "policy_issue_dtl"

    <Serializable()> _
    Public Class POLICY_ISSUE_DTL_VO

        Public POLICY_ISSUE_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_CLIENT_CD As String
        Public POLICY_ISSUE_DT As Date
        Public ISSUE_TYPE As String
        Public ISSUE_ST As String
        Public REMARKS As String
        Public POLICY_ISSUE_CREA_BY As String
        Public POLICY_ISSUE_CREA_DT As Date
        Public POLICY_ISSUE_LAST_UPD_BY As String
        Public POLICY_ISSUE_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_ISSUE_DTL As Short
            NONE = 0
            policy_issue_cd = 1
            policy_seq_cd = 2
            policy_client_cd = 4
            policy_issue_dt = 8
            issue_type = 16
            issue_st = 32
            remarks = 64
            policy_issue_crea_by = 128
            policy_issue_crea_dt = 256
            policy_issue_last_upd_by = 512
            policy_issue_last_upd_dt = 1024
        End Enum

    End Class

    Public Class POLICY_ISSUE_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_ISSUE_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_issue_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_ISSUE_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_ISSUE_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_issue_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_ISSUE_DTL_VO, Optional ByVal ExcludeValue As POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM POLICY_ISSUE_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_ISSUE_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL = POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.POLICY_ISSUE_CD) Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_seq_cd
                If Not IsNothing(.POLICY_CLIENT_CD) Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_client_cd
                If Year(.POLICY_ISSUE_DT) > 1 Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_dt
                If Not IsNothing(.ISSUE_TYPE) Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.issue_type
                If Not IsNothing(.ISSUE_ST) Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.issue_st
                If Not IsNothing(.REMARKS) Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.remarks
                If Not IsNothing(.POLICY_ISSUE_CREA_BY) Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_crea_by
                If Year(.POLICY_ISSUE_CREA_DT) > 1 Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_crea_dt
                If Not IsNothing(.POLICY_ISSUE_LAST_UPD_BY) Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_last_upd_by
                If Year(.POLICY_ISSUE_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE POLICY_ISSUE_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO POLICY_ISSUE_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM POLICY_ISSUE_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_cd) Then
                            .Append("POLICY_ISSUE_CD")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_cd

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_client_cd) Then
                            .Append("POLICY_CLIENT_CD")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_client_cd

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_dt) Then
                            .Append("POLICY_ISSUE_DT")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_dt

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.issue_type) Then
                            .Append("ISSUE_TYPE")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.issue_type

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.issue_st) Then
                            .Append("ISSUE_ST")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.issue_st

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.remarks) Then
                            .Append("REMARKS")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.remarks

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_crea_by) Then
                            .Append("POLICY_ISSUE_CREA_BY")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_crea_dt) Then
                            .Append("POLICY_ISSUE_CREA_DT")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_last_upd_by) Then
                            .Append("POLICY_ISSUE_LAST_UPD_BY")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_last_upd_dt) Then
                            .Append("POLICY_ISSUE_LAST_UPD_DT")
                            shrtFlag -= POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_ISSUE_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL = POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_ISSUE_CD) And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_cd) Then .AddWithValue("@policy_issue_cd", Value.POLICY_ISSUE_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.POLICY_CLIENT_CD) And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_client_cd) Then .AddWithValue("@policy_client_cd", Value.POLICY_CLIENT_CD)
                If Year(Value.POLICY_ISSUE_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_dt) Then .AddWithValue("@policy_issue_dt", Value.POLICY_ISSUE_DT)
                If Not IsNothing(Value.ISSUE_TYPE) And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.issue_type) Then .AddWithValue("@issue_type", Value.ISSUE_TYPE)
                If Not IsNothing(Value.ISSUE_ST) And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.issue_st) Then .AddWithValue("@issue_st", Value.ISSUE_ST)
                If Not IsNothing(Value.REMARKS) And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.remarks) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not IsNothing(Value.POLICY_ISSUE_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_crea_by) Then .AddWithValue("@policy_issue_crea_by", Value.POLICY_ISSUE_CREA_BY)
                If Year(Value.POLICY_ISSUE_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_crea_dt) Then .AddWithValue("@policy_issue_crea_dt", Value.POLICY_ISSUE_CREA_DT)
                If Not IsNothing(Value.POLICY_ISSUE_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_last_upd_by) Then .AddWithValue("@policy_issue_last_upd_by", Value.POLICY_ISSUE_LAST_UPD_BY)
                If Year(Value.POLICY_ISSUE_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_ISSUE_DTL_VO.Enum_POLICY_ISSUE_DTL.policy_issue_last_upd_dt) Then .AddWithValue("@policy_issue_last_upd_dt", Value.POLICY_ISSUE_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "policy_ref_dtl"

    <Serializable()> _
    Public Class POLICY_REF_DTL_VO

        Public REFERRAL_CD As String
        Public POLICY_SEQ_NO As String
        Public USER_NAME As String
        Public REF_LAST_NAME As String
        Public REF_FIRST_NAME As String
        Public REF_MIDDLE_NAME As String
        Public REMARKS As String
        Public STATUS_CD As String
        Public REF_CREA_BY As String
        Public REF_CREA_DT As Date
        Public REF_LAST_UPD_BY As String
        Public REF_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_REF_DTL As Short
            NONE = 0
            referral_cd = 1
            policy_seq_no = 2
            user_name = 4
            ref_last_name = 8
            ref_first_name = 16
            ref_middle_name = 32
            remarks = 64
            status_cd = 128
            ref_crea_by = 256
            ref_crea_dt = 512
            ref_last_upd_by = 1024
            ref_last_upd_dt = 2048
        End Enum

    End Class

    Public Class POLICY_REF_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_REF_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_ref_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_REF_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_REF_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_ref_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_REF_DTL_VO, Optional ByVal ExcludeValue As POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM POLICY_REF_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_REF_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL = POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.REFERRAL_CD) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.referral_cd
                If Not IsNothing(.POLICY_SEQ_NO) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.policy_seq_no
                If Not IsNothing(.USER_NAME) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.user_name
                If Not IsNothing(.REF_LAST_NAME) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_name
                If Not IsNothing(.REF_FIRST_NAME) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_first_name
                If Not IsNothing(.REF_MIDDLE_NAME) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_middle_name
                If Not IsNothing(.REMARKS) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.remarks
                If Not IsNothing(.STATUS_CD) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.status_cd
                If Not IsNothing(.REF_CREA_BY) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_crea_by
                If Year(.REF_CREA_DT) > 1 Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_crea_dt
                If Not IsNothing(.REF_LAST_UPD_BY) Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_upd_by
                If Year(.REF_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE POLICY_REF_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO POLICY_REF_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM POLICY_REF_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.referral_cd) Then
                            .Append("REFERRAL_CD")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.referral_cd

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.policy_seq_no) Then
                            .Append("POLICY_SEQ_NO")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.policy_seq_no

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.user_name) Then
                            .Append("USER_NAME")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.user_name

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_name) Then
                            .Append("REF_LAST_NAME")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_name

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_first_name) Then
                            .Append("REF_FIRST_NAME")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_first_name

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_middle_name) Then
                            .Append("REF_MIDDLE_NAME")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_middle_name

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.remarks) Then
                            .Append("REMARKS")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.remarks

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.status_cd) Then
                            .Append("STATUS_CD")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.status_cd

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_crea_by) Then
                            .Append("REF_CREA_BY")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_crea_dt) Then
                            .Append("REF_CREA_DT")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_upd_by) Then
                            .Append("REF_LAST_UPD_BY")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_upd_dt) Then
                            .Append("REF_LAST_UPD_DT")
                            shrtFlag -= POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_REF_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL = POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.REFERRAL_CD) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.referral_cd) Then .AddWithValue("@referral_cd", Value.REFERRAL_CD)
                If Not IsNothing(Value.POLICY_SEQ_NO) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.policy_seq_no) Then .AddWithValue("@policy_seq_no", Value.POLICY_SEQ_NO)
                If Not IsNothing(Value.USER_NAME) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.user_name) Then .AddWithValue("@user_name", Value.USER_NAME)
                If Not IsNothing(Value.REF_LAST_NAME) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_name) Then .AddWithValue("@ref_last_name", Value.REF_LAST_NAME)
                If Not IsNothing(Value.REF_FIRST_NAME) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_first_name) Then .AddWithValue("@ref_first_name", Value.REF_FIRST_NAME)
                If Not IsNothing(Value.REF_MIDDLE_NAME) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_middle_name) Then .AddWithValue("@ref_middle_name", Value.REF_MIDDLE_NAME)
                If Not IsNothing(Value.REMARKS) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.remarks) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not IsNothing(Value.STATUS_CD) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.status_cd) Then .AddWithValue("@status_cd", Value.STATUS_CD)
                If Not IsNothing(Value.REF_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_crea_by) Then .AddWithValue("@ref_crea_by", Value.REF_CREA_BY)
                If Year(Value.REF_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_crea_dt) Then .AddWithValue("@ref_crea_dt", Value.REF_CREA_DT)
                If Not IsNothing(Value.REF_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_upd_by) Then .AddWithValue("@ref_last_upd_by", Value.REF_LAST_UPD_BY)
                If Year(Value.REF_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_REF_DTL_VO.Enum_POLICY_REF_DTL.ref_last_upd_dt) Then .AddWithValue("@ref_last_upd_dt", Value.REF_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "policy_premium_dtl"

    <Serializable()> _
    Public Class POLICY_PREMIUM_DTL_VO

        Public POLICY_PREMIUM_CD As String
        Public POLICY_SEQ_CD As String
        Public POLICY_DUE_DT As Date
        Public CURRENCY_CD As String
        Public CONTRIBUTION_AMT As Double = -1
        Public PAY_TAG As Integer = -1

        Public Enum Enum_POLICY_PREMIUM_DTL As Short
            NONE = 0
            policy_premium_cd = 1
            policy_seq_cd = 2
            policy_due_dt = 4
            currency_cd = 8
            contribution_amt = 16
            pay_tag = 32
        End Enum

    End Class

    Public Class POLICY_PREMIUM_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_PREMIUM_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_premium_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_PREMIUM_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    '.CommandType = CommandType.StoredProcedure
                    '.CommandText = "sp_policy_premium_dtl_del"
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_PREMIUM_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_premium_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_PREMIUM_DTL_VO, Optional ByVal ExcludeValue As POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM policy_premium_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_PREMIUM_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL = POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.POLICY_PREMIUM_CD) Then shrtFlag += POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_premium_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_seq_cd
                If Year(.POLICY_DUE_DT) > 1 Then shrtFlag += POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_due_dt
                If Not IsNothing(.CURRENCY_CD) Then shrtFlag += POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.currency_cd
                If .CONTRIBUTION_AMT >= 0 Then shrtFlag += POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.contribution_amt
                If .PAY_TAG >= 0 Then shrtFlag += POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.pay_tag
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE policy_premium_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO policy_premium_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM policy_premium_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_premium_cd) Then
                            .Append("POLICY_PREMIUM_CD")
                            shrtFlag -= POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_premium_cd

                        ElseIf CheckBit(shrtFlag, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_due_dt) Then
                            .Append("POLICY_DUE_DT")
                            shrtFlag -= POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_due_dt

                        ElseIf CheckBit(shrtFlag, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.currency_cd) Then
                            .Append("CURRENCY_CD")
                            shrtFlag -= POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.currency_cd

                        ElseIf CheckBit(shrtFlag, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.contribution_amt) Then
                            .Append("CONTRIBUTION_AMT")
                            shrtFlag -= POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.contribution_amt

                        ElseIf CheckBit(shrtFlag, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.pay_tag) Then
                            .Append("PAY_TAG")
                            shrtFlag -= POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.pay_tag

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_PREMIUM_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL = POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_premium_cd) Then .AddWithValue("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Year(Value.POLICY_DUE_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.policy_due_dt) Then .AddWithValue("@policy_due_dt", Value.POLICY_DUE_DT)
                If Not IsNothing(Value.CURRENCY_CD) And Not CheckBit(ExcludeValue, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.currency_cd) Then .AddWithValue("@currency_cd", Value.CURRENCY_CD)
                If Value.CONTRIBUTION_AMT >= 0 And Not CheckBit(ExcludeValue, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.contribution_amt) Then .AddWithValue("@contribution_amt", Value.CONTRIBUTION_AMT)
                If Value.PAY_TAG >= 0 And Not CheckBit(ExcludeValue, POLICY_PREMIUM_DTL_VO.Enum_POLICY_PREMIUM_DTL.pay_tag) Then .AddWithValue("@pay_tag", Value.PAY_TAG)
            End With
        End Sub
    End Class

#End Region

#Region "policy_trans_attach_dtl"

    <Serializable()> _
    Public Class POLICY_TRANS_ATTACH_DTL_VO

        Public POLICY_ATTACH_CD As String
        Public POLICY_SEQ_CD As String
        Public FILENAME As String
        Public CAPTION As String
        Public POLICY_ATTACH_CREA_BY As String
        Public POLICY_ATTACH_CREA_DT As Date
        Public POLICY_ATTACH_LAST_UPD_BY As String
        Public POLICY_ATTACH_LAST_UPD_DT As Date

        Public Enum Enum_POLICY_TRANS_ATTACH_DTL As Short
            NONE = 0
            policy_attach_cd = 1
            policy_seq_cd = 2
            filename = 4
            caption = 8
            policy_attach_crea_by = 16
            policy_attach_crea_dt = 32
            policy_attach_last_upd_by = 64
            policy_attach_last_upd_dt = 128
        End Enum

    End Class

    Public Class POLICY_TRANS_ATTACH_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_TRANS_ATTACH_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_trans_attach_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_TRANS_ATTACH_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_TRANS_ATTACH_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_trans_attach_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_TRANS_ATTACH_DTL_VO, Optional ByVal ExcludeValue As POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM policy_trans_attach_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_TRANS_ATTACH_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL = POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.POLICY_ATTACH_CD) Then shrtFlag += POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_cd
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_seq_cd
                If Not IsNothing(.FILENAME) Then shrtFlag += POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.filename
                If Not IsNothing(.CAPTION) Then shrtFlag += POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.caption
                If Not IsNothing(.POLICY_ATTACH_CREA_BY) Then shrtFlag += POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_by
                If Year(.POLICY_ATTACH_CREA_DT) > 1 Then shrtFlag += POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_dt
                If Not IsNothing(.POLICY_ATTACH_LAST_UPD_BY) Then shrtFlag += POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_by
                If Year(.POLICY_ATTACH_LAST_UPD_DT) > 1 Then shrtFlag += POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE policy_trans_attach_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO policy_trans_attach_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM policy_trans_attach_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_cd) Then
                            .Append("POLICY_ATTACH_CD")
                            shrtFlag -= POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_cd

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.filename) Then
                            .Append("FILENAME")
                            shrtFlag -= POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.filename

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.caption) Then
                            .Append("CAPTION")
                            shrtFlag -= POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.caption

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_by) Then
                            .Append("POLICY_ATTACH_CREA_BY")
                            shrtFlag -= POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_by

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_dt) Then
                            .Append("POLICY_ATTACH_CREA_DT")
                            shrtFlag -= POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_dt

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_by) Then
                            .Append("POLICY_ATTACH_LAST_UPD_BY")
                            shrtFlag -= POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_by

                        ElseIf CheckBit(shrtFlag, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_dt) Then
                            .Append("POLICY_ATTACH_LAST_UPD_DT")
                            shrtFlag -= POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_TRANS_ATTACH_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL = POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_ATTACH_CD) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_cd) Then .AddWithValue("@policy_attach_cd", Value.POLICY_ATTACH_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.FILENAME) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.filename) Then .AddWithValue("@filename", Value.FILENAME)
                If Not IsNothing(Value.CAPTION) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.caption) Then .AddWithValue("@caption", Value.CAPTION)
                If Not IsNothing(Value.POLICY_ATTACH_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_by) Then .AddWithValue("@policy_attach_crea_by", Value.POLICY_ATTACH_CREA_BY)
                If Year(Value.POLICY_ATTACH_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_dt) Then .AddWithValue("@policy_attach_crea_dt", Value.POLICY_ATTACH_CREA_DT)
                If Not IsNothing(Value.POLICY_ATTACH_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_by) Then .AddWithValue("@policy_attach_last_upd_by", Value.POLICY_ATTACH_LAST_UPD_BY)
                If Year(Value.POLICY_ATTACH_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_dt) Then .AddWithValue("@policy_attach_last_upd_dt", Value.POLICY_ATTACH_LAST_UPD_DT)
            End With
        End Sub
        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As POLICY_TRANS_ATTACH_DTL_VO, Optional ByVal ExcludeValue As POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL = POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.NONE)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not IsNothing(Value.POLICY_ATTACH_CD) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_cd) Then .Add("@policy_attach_cd", Value.POLICY_ATTACH_CD)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_seq_cd) Then .Add("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.FILENAME) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.filename) Then .Add("@filename", Value.FILENAME)
                If Not IsNothing(Value.CAPTION) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.caption) Then .Add("@caption", Value.CAPTION)
                If Not IsNothing(Value.POLICY_ATTACH_CREA_BY) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_by) Then .Add("@policy_attach_crea_by", Value.POLICY_ATTACH_CREA_BY)
                If Year(Value.POLICY_ATTACH_CREA_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_crea_dt) Then .Add("@policy_attach_crea_dt", Value.POLICY_ATTACH_CREA_DT)
                If Not IsNothing(Value.POLICY_ATTACH_LAST_UPD_BY) And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_by) Then .Add("@policy_attach_last_upd_by", Value.POLICY_ATTACH_LAST_UPD_BY)
                If Year(Value.POLICY_ATTACH_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL.policy_attach_last_upd_dt) Then .Add("@policy_attach_last_upd_dt", Value.POLICY_ATTACH_LAST_UPD_DT)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As POLICY_TRANS_ATTACH_DTL_VO, Optional ByVal ExcludeValue As POLICY_TRANS_ATTACH_DTL_VO.Enum_POLICY_TRANS_ATTACH_DTL = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM policy_trans_attach_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "payment_dtl"

    <Serializable()> _
    Public Class PAYMENT_DTL_VO

        Public PAYMENT_SEQ_CD As String
        Public PAYMENT_NO As String
        Public POLICY_SEQ_CD As String
        Public POLICY_PREMIUM_CD As String
        Public PAYMENT_DT As Date
        Public PAYMENT_FORM As String
        Public PAYMENT_AMT As Double = -1
        Public REMARKS As String
        Public DISPATCH_NO As String
        Public CONFIRM_NO As String
        Public PAYMENT_STATUS As String
        Public PAYMENT_CREA_BY As String
        Public PAYMENT_CREA_DT As String
        Public PAYMENT_LAST_UPD_BY As String
        Public PAYMENT_LAST_UPD_DT As Date
        Public AR_DATE As Date

        Public Enum Enum_payment_dtl As Integer
            NONE = 0
            payment_seq_cd = 1
            payment_no = 2
            policy_seq_cd = 4
            policy_premium_cd = 8
            payment_dt = 16
            payment_form = 32
            payment_amt = 64
            remarks = 128
            dispatch_no = 256
            confirm_no = 512
            payment_status = 1024
            payment_crea_by = 2048
            payment_crea_dt = 4096
            payment_last_upd_by = 8192
            payment_last_upd_dt = 16384
            ar_date = 32768
        End Enum

    End Class

    Public Class PAYMENT_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As PAYMENT_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_payment_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As PAYMENT_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As PAYMENT_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_payment_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As PAYMENT_DTL_VO, Optional ByVal ExcludeValue As PAYMENT_DTL_VO.Enum_payment_dtl = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM payment_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As PAYMENT_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As PAYMENT_DTL_VO.Enum_payment_dtl = PAYMENT_DTL_VO.Enum_payment_dtl.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not IsNothing(.PAYMENT_SEQ_CD) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_seq_cd
                If Not IsNothing(.PAYMENT_NO) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_no
                If Not IsNothing(.POLICY_SEQ_CD) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.policy_seq_cd
                If Not IsNothing(.POLICY_PREMIUM_CD) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.policy_premium_cd
                If Year(.PAYMENT_DT) > 1 Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_dt
                If Not IsNothing(.PAYMENT_FORM) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_form
                If .PAYMENT_AMT >= 0 Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_amt
                If Not IsNothing(.REMARKS) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.remarks
                If Not IsNothing(.DISPATCH_NO) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.dispatch_no
                If Not IsNothing(.CONFIRM_NO) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.confirm_no
                If Not IsNothing(.PAYMENT_STATUS) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_status
                If Not IsNothing(.PAYMENT_CREA_BY) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_by
                If Not IsNothing(.PAYMENT_CREA_DT) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_dt
                If Not IsNothing(.PAYMENT_LAST_UPD_BY) Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_by
                If Year(.PAYMENT_LAST_UPD_DT) > 1 Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_dt
                If Year(.AR_DATE) > 1 Then shrtFlag += PAYMENT_DTL_VO.Enum_payment_dtl.ar_date
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> PAYMENT_DTL_VO.Enum_payment_dtl.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE payment_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO payment_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM payment_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_seq_cd) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_seq_cd

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_no) Then
                            .Append("PAYMENT_NO")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_no

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.policy_seq_cd) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.policy_seq_cd

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.policy_premium_cd) Then
                            .Append("POLICY_PREMIUM_CD")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.policy_premium_cd

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_dt) Then
                            .Append("PAYMENT_DT")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_dt

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_form) Then
                            .Append("PAYMENT_FORM")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_form

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_amt) Then
                            .Append("PAYMENT_AMT")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_amt

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.remarks) Then
                            .Append("REMARKS")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.remarks

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.dispatch_no) Then
                            .Append("DISPATCH_NO")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.dispatch_no

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.confirm_no) Then
                            .Append("CONFIRM_NO")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.confirm_no

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_status) Then
                            .Append("PAYMENT_STATUS")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_status

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_by) Then
                            .Append("PAYMENT_CREA_BY")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_by

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_dt) Then
                            .Append("PAYMENT_CREA_DT")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_dt

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_by) Then
                            .Append("PAYMENT_LAST_UPD_BY")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_by

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_dt) Then
                            .Append("PAYMENT_LAST_UPD_DT")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_dt

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO.Enum_payment_dtl.ar_date) Then
                            .Append("AR_DATE")
                            shrtFlag -= PAYMENT_DTL_VO.Enum_payment_dtl.ar_date

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As PAYMENT_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As PAYMENT_DTL_VO.Enum_payment_dtl = PAYMENT_DTL_VO.Enum_payment_dtl.NONE)
            With Command.Parameters
                If Not IsNothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_seq_cd) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not IsNothing(Value.PAYMENT_NO) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_no) Then .AddWithValue("@payment_no", Value.PAYMENT_NO)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.policy_seq_cd) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.policy_premium_cd) Then .AddWithValue("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Year(Value.PAYMENT_DT) > 1 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_dt) Then .AddWithValue("@payment_dt", Value.PAYMENT_DT)
                If Not IsNothing(Value.PAYMENT_FORM) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_form) Then .AddWithValue("@payment_form", Value.PAYMENT_FORM)
                If Value.PAYMENT_AMT >= 0 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_amt) Then .AddWithValue("@payment_amt", Value.PAYMENT_AMT)
                If Not IsNothing(Value.REMARKS) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.remarks) Then .AddWithValue("@remarks", Value.REMARKS)
                If Not IsNothing(Value.DISPATCH_NO) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.dispatch_no) Then .AddWithValue("@dispatch_no", Value.DISPATCH_NO)
                If Not IsNothing(Value.CONFIRM_NO) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.confirm_no) Then .AddWithValue("@confirm_no", Value.CONFIRM_NO)
                If Not IsNothing(Value.PAYMENT_STATUS) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_status) Then .AddWithValue("@payment_status", Value.PAYMENT_STATUS)
                If Not IsNothing(Value.PAYMENT_CREA_BY) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_by) Then .AddWithValue("@payment_crea_by", Value.PAYMENT_CREA_BY)
                If Not IsNothing(Value.PAYMENT_CREA_DT) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_dt) Then .AddWithValue("@payment_crea_dt", Value.PAYMENT_CREA_DT)
                If Not IsNothing(Value.PAYMENT_LAST_UPD_BY) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_by) Then .AddWithValue("@payment_last_upd_by", Value.PAYMENT_LAST_UPD_BY)
                If Year(Value.PAYMENT_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_dt) Then .AddWithValue("@payment_last_upd_dt", Value.PAYMENT_LAST_UPD_DT)
                If Year(Value.AR_DATE) > 1 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.ar_date) Then .AddWithValue("@ar_date", Value.AR_DATE)
            End With
        End Sub
        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As PAYMENT_DTL_VO, Optional ByVal ExcludeValue As PAYMENT_DTL_VO.Enum_payment_dtl = PAYMENT_DTL_VO.Enum_payment_dtl.NONE)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not IsNothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_seq_cd) Then .Add("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not IsNothing(Value.PAYMENT_NO) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_no) Then .Add("@payment_no", Value.PAYMENT_NO)
                If Not IsNothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.policy_seq_cd) Then .Add("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not IsNothing(Value.POLICY_PREMIUM_CD) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.policy_premium_cd) Then .Add("@policy_premium_cd", Value.POLICY_PREMIUM_CD)
                If Year(Value.PAYMENT_DT) > 1 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_dt) Then .Add("@payment_dt", Value.PAYMENT_DT)
                If Not IsNothing(Value.PAYMENT_FORM) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_form) Then .Add("@payment_form", Value.PAYMENT_FORM)
                If Value.PAYMENT_AMT >= 0 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_amt) Then .Add("@payment_amt", Value.PAYMENT_AMT)
                If Not IsNothing(Value.REMARKS) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.remarks) Then .Add("@remarks", Value.REMARKS)
                If Not IsNothing(Value.DISPATCH_NO) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.dispatch_no) Then .Add("@dispatch_no", Value.DISPATCH_NO)
                If Not IsNothing(Value.CONFIRM_NO) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.confirm_no) Then .Add("@confirm_no", Value.CONFIRM_NO)
                If Not IsNothing(Value.PAYMENT_STATUS) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_status) Then .Add("@payment_status", Value.PAYMENT_STATUS)
                If Not IsNothing(Value.PAYMENT_CREA_BY) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_by) Then .Add("@payment_crea_by", Value.PAYMENT_CREA_BY)
                If Not IsNothing(Value.PAYMENT_CREA_DT) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_crea_dt) Then .Add("@payment_crea_dt", Value.PAYMENT_CREA_DT)
                If Not IsNothing(Value.PAYMENT_LAST_UPD_BY) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_by) Then .Add("@payment_last_upd_by", Value.PAYMENT_LAST_UPD_BY)
                If Year(Value.PAYMENT_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.payment_last_upd_dt) Then .Add("@payment_last_upd_dt", Value.PAYMENT_LAST_UPD_DT)
                If Year(Value.AR_DATE) > 1 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO.Enum_payment_dtl.ar_date) Then .Add("@ar_date", Value.AR_DATE)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As PAYMENT_DTL_VO, Optional ByVal ExcludeValue As PAYMENT_DTL_VO.Enum_payment_dtl = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM payment_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "payment_dtl_dispatch"

    <Serializable()> _
    Public Class PAYMENT_DTL_VO_DISPATCH

        Public PAYMENT_SEQ_CD As String
        Public PAYMENT_LAST_UPD_BY As String
        Public PAYMENT_LAST_UPD_DT As Date

        Public Enum Enum_PAYMENT_DTL_dispatch As Short
            NONE = 0
            payment_seq_cd = 1
            payment_last_upd_by = 2
            payment_last_upd_dt = 4
        End Enum

    End Class

    Public Class PAYMENT_DTL_DAO_DISPATCH
        Inherits CommonDAO

        Public Overloads Function Update(ByVal Value As PAYMENT_DTL_VO_DISPATCH) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_payment_dtl_upd_dispatch"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Private Function QueryBuilder(ByVal Value As PAYMENT_DTL_VO_DISPATCH, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch = PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.PAYMENT_SEQ_CD) Then shrtFlag += PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_seq_cd
                If Not IsNothing(.PAYMENT_LAST_UPD_BY) Then shrtFlag += PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_last_upd_by
                If Year(.PAYMENT_LAST_UPD_DT) > 1 Then shrtFlag += PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE payment_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO payment_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM payment_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_seq_cd) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_seq_cd

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_last_upd_by) Then
                            .Append("PAYMENT_LAST_UPD_BY")
                            shrtFlag -= PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_last_upd_by

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_last_upd_dt) Then
                            .Append("PAYMENT_LAST_UPD_DT")
                            shrtFlag -= PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As PAYMENT_DTL_VO_DISPATCH, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch = PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.NONE)
            With Command.Parameters
                If Not IsNothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_seq_cd) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not IsNothing(Value.PAYMENT_LAST_UPD_BY) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_last_upd_by) Then .AddWithValue("@payment_last_upd_by", Value.PAYMENT_LAST_UPD_BY)
                If Year(Value.PAYMENT_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO_DISPATCH.Enum_PAYMENT_DTL_dispatch.payment_last_upd_dt) Then .AddWithValue("@payment_last_upd_dt", Value.PAYMENT_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "policy_dispatch_dtl"

    <Serializable()> _
    Public Class POLICY_DISPATCH_DTL_VO

        Public POLICY_DISPATCH_CD As String
        Public PAYMENT_SEQ_CD As String
        Public POLICY_DISPATCH_ATTACHMENT As String
        Public POLICY_DISPATCH_DATE As Date

        Public Enum Enum_POLICY_DISPATCH_DTL As Short
            NONE = 0
            policy_dispatch_cd = 1
            payment_seq_cd = 2
            policy_dispatch_attachment = 4
            policy_dispatch_date = 8
        End Enum

    End Class

    Public Class POLICY_DISPATCH_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As policy_dispatch_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_dispatch_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As policy_dispatch_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As policy_dispatch_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_dispatch_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As policy_dispatch_dtl_VO, Optional ByVal ExcludeValue As policy_dispatch_dtl_VO.Enum_policy_dispatch_dtl = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM policy_dispatch_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_DISPATCH_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl = POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.POLICY_DISPATCH_CD) Then shrtFlag += POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_CD
                If Not isnothing(.PAYMENT_SEQ_CD) Then shrtFlag += POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.PAYMENT_SEQ_CD
                If Not isnothing(.POLICY_DISPATCH_ATTACHMENT) Then shrtFlag += POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_ATTACHMENT
                If Year(.POLICY_DISPATCH_DATE) > 1 Then shrtFlag += POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_DATE
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE policy_dispatch_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO policy_dispatch_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM policy_dispatch_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_CD) Then
                            .Append("POLICY_DISPATCH_CD")
                            shrtFlag -= POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_CD

                        ElseIf CheckBit(shrtFlag, POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.PAYMENT_SEQ_CD) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.PAYMENT_SEQ_CD

                        ElseIf CheckBit(shrtFlag, POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_ATTACHMENT) Then
                            .Append("POLICY_DISPATCH_ATTACHMENT")
                            shrtFlag -= POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_ATTACHMENT

                        ElseIf CheckBit(shrtFlag, POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_DATE) Then
                            .Append("POLICY_DISPATCH_DATE")
                            shrtFlag -= POLICY_DISPATCH_DTL_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_DATE

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As policy_dispatch_dtl_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As policy_dispatch_dtl_VO.Enum_policy_dispatch_dtl = policy_dispatch_dtl_VO.Enum_policy_dispatch_dtl.None)
            With Command.Parameters
                If Not isnothing(Value.POLICY_DISPATCH_CD) And Not CheckBit(ExcludeValue, policy_dispatch_dtl_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_CD) Then .AddWithValue("@policy_dispatch_cd", Value.POLICY_DISPATCH_CD)
                If Not isnothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, policy_dispatch_dtl_VO.Enum_policy_dispatch_dtl.PAYMENT_SEQ_CD) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not isnothing(Value.POLICY_DISPATCH_ATTACHMENT) And Not CheckBit(ExcludeValue, policy_dispatch_dtl_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_ATTACHMENT) Then .AddWithValue("@policy_dispatch_attachment", Value.POLICY_DISPATCH_ATTACHMENT)
                If Year(Value.POLICY_DISPATCH_DATE) > 1 And Not CheckBit(ExcludeValue, policy_dispatch_dtl_VO.Enum_policy_dispatch_dtl.POLICY_DISPATCH_DATE) Then .AddWithValue("@policy_dispatch_date", Value.POLICY_DISPATCH_DATE)
            End With
        End Sub
        Public Function GetQuery(ByVal Value As policy_dispatch_dtl_VO, Optional ByVal ExcludeValue As policy_dispatch_dtl_VO.Enum_policy_dispatch_dtl = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM policy_dispatch_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "policy_confirm_dtl"

    <Serializable()> _
    Public Class POLICY_CONFIRM_DTL_VO

        Public POLICY_CONFIRM_CD As String
        Public PAYMENT_SEQ_CD As String
        Public POLICY_CONFIRM_DT As Date

        Public Enum Enum_POLICY_CONFIRM_DTL As Short
            NONE = 0
            policy_confirm_cd = 1
            payment_seq_cd = 2
            policy_confirm_dt = 4
        End Enum

    End Class

    Public Class POLICY_CONFIRM_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As POLICY_CONFIRM_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_policy_confirm_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As POLICY_CONFIRM_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As POLICY_CONFIRM_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_policy_confirm_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As POLICY_CONFIRM_DTL_VO, Optional ByVal ExcludeValue As POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM policy_confirm_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As POLICY_CONFIRM_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL = POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.POLICY_CONFIRM_CD) Then shrtFlag += POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.policy_confirm_cd
                If Not IsNothing(.PAYMENT_SEQ_CD) Then shrtFlag += POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.payment_seq_cd
                If Year(.POLICY_CONFIRM_DT) > 1 Then shrtFlag += POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.policy_confirm_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE policy_confirm_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO policy_confirm_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM policy_confirm_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.policy_confirm_cd) Then
                            .Append("POLICY_CONFIRM_CD")
                            shrtFlag -= POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.policy_confirm_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.payment_seq_cd) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.payment_seq_cd

                        ElseIf CheckBit(shrtFlag, POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.policy_confirm_dt) Then
                            .Append("POLICY_CONFIRM_DT")
                            shrtFlag -= POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.policy_confirm_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As POLICY_CONFIRM_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL = POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.POLICY_CONFIRM_CD) And Not CheckBit(ExcludeValue, POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.policy_confirm_cd) Then .AddWithValue("@policy_confirm_cd", Value.POLICY_CONFIRM_CD)
                If Not IsNothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.payment_seq_cd) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Year(Value.POLICY_CONFIRM_DT) > 1 And Not CheckBit(ExcludeValue, POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL.policy_confirm_dt) Then .AddWithValue("@policy_confirm_dt", Value.POLICY_CONFIRM_DT)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As POLICY_CONFIRM_DTL_VO, Optional ByVal ExcludeValue As POLICY_CONFIRM_DTL_VO.Enum_POLICY_CONFIRM_DTL = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM policy_confirm_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "payment_dtl_confirm"

    <Serializable()> _
    Public Class PAYMENT_DTL_VO_CONFIRM

        Public PAYMENT_SEQ_CD As String
        Public PAYMENT_LAST_UPD_BY As String
        Public PAYMENT_LAST_UPD_DT As Date

        Public Enum Enum_PAYMENT_DTL_confirm As Short
            NONE = 0
            payment_seq_cd = 1
            payment_last_upd_by = 2
            payment_last_upd_dt = 4
        End Enum

    End Class

    Public Class PAYMENT_DTL_DAO_CONFIRM
        Inherits CommonDAO

        Public Overloads Function Update(ByVal Value As PAYMENT_DTL_VO_CONFIRM) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_payment_dtl_upd_confirm"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Private Function QueryBuilder(ByVal Value As PAYMENT_DTL_VO_CONFIRM, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm = PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.PAYMENT_SEQ_CD) Then shrtFlag += PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_seq_cd
                If Not IsNothing(.PAYMENT_LAST_UPD_BY) Then shrtFlag += PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_last_upd_by
                If Year(.PAYMENT_LAST_UPD_DT) > 1 Then shrtFlag += PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE payment_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO payment_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM payment_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_seq_cd) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_seq_cd

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_last_upd_by) Then
                            .Append("PAYMENT_LAST_UPD_BY")
                            shrtFlag -= PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_last_upd_by

                        ElseIf CheckBit(shrtFlag, PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_last_upd_dt) Then
                            .Append("PAYMENT_LAST_UPD_DT")
                            shrtFlag -= PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As PAYMENT_DTL_VO_CONFIRM, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm = PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.NONE)
            With Command.Parameters
                If Not IsNothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_seq_cd) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not IsNothing(Value.PAYMENT_LAST_UPD_BY) And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_last_upd_by) Then .AddWithValue("@payment_last_upd_by", Value.PAYMENT_LAST_UPD_BY)
                If Year(Value.PAYMENT_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, PAYMENT_DTL_VO_CONFIRM.Enum_PAYMENT_DTL_confirm.payment_last_upd_dt) Then .AddWithValue("@payment_last_upd_dt", Value.PAYMENT_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "commission_payable_dtl"

    <Serializable()> _
    Public Class COMMISSION_PAYABLE_DTL_VO

        Public COM_PAY_SEQ_CD As String
        Public POLICY_SEQ_CD As String
        Public PAYMENT_SEQ_CD As String
        Public ADVISOR_CD As String
        Public COM_DT As Date
        Public COM_RATE As Double = -1
        Public COM_AMT As Double = -1
        Public COM_CURR_CD As String
        Public CONV_RATE As Double = -1
        Public CONV_COM_AMT As Double = -1
        Public CONV_CURR_CD As String
        Public COM_REC_RATE As Double = -1
        Public COM_REC_AMT As Double = -1
        Public COM_TYPE As String
        Public COM_ST As String
        Public COM_CREA_BY As String
        Public COM_CREA_DT As Date
        Public COM_LAST_UPD_BY As String
        Public COM_LAST_UPD_DT As Date

        Public Enum Enum_commission_payable_dtl As Integer
            NONE = 0
            com_pay_seq_cd = 1
            policy_seq_cd = 2
            payment_seq_cd = 4
            advisor_cd = 8
            com_dt = 16
            com_rate = 32
            com_amt = 64
            com_curr_cd = 128
            conv_rate = 256
            conv_com_amt = 512
            conv_curr_cd = 1024
            com_rec_rate = 2048
            com_rec_amt = 4096
            com_type = 8192
            com_st = 16384
            com_crea_by = 32768
            com_crea_dt = 65536
            com_last_upd_by = 131072
            com_last_upd_dt = 262144
        End Enum

    End Class

    Public Class COMMISSION_PAYABLE_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As commission_payable_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_commission_payable_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As commission_payable_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As commission_payable_dtl_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_commission_payable_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As commission_payable_dtl_VO, Optional ByVal ExcludeValue As commission_payable_dtl_VO.Enum_commission_payable_dtl = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM commission_payable_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As COMMISSION_PAYABLE_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl = COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not isnothing(.COM_PAY_SEQ_CD) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_PAY_SEQ_CD
                If Not isnothing(.POLICY_SEQ_CD) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.POLICY_SEQ_CD
                If Not isnothing(.PAYMENT_SEQ_CD) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.PAYMENT_SEQ_CD
                If Not isnothing(.ADVISOR_CD) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.ADVISOR_CD
                If Year(.COM_DT) > 1 Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_DT
                If .COM_RATE >= 0 Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_RATE
                If .COM_AMT >= 0 Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_AMT
                If Not isnothing(.COM_CURR_CD) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_CURR_CD
                If .CONV_RATE >= 0 Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.CONV_RATE
                If .CONV_COM_AMT >= 0 Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.CONV_COM_AMT
                If Not isnothing(.CONV_CURR_CD) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.CONV_CURR_CD
                If .COM_REC_RATE >= 0 Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_REC_RATE
                If .COM_REC_AMT >= 0 Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_REC_AMT
                If Not isnothing(.COM_TYPE) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_TYPE
                If Not isnothing(.COM_ST) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_ST
                If Not isnothing(.COM_CREA_BY) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_CREA_BY
                If Year(.COM_CREA_DT) > 1 Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_CREA_DT
                If Not isnothing(.COM_LAST_UPD_BY) Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_LAST_UPD_BY
                If Year(.COM_LAST_UPD_DT) > 1 Then shrtFlag += COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_LAST_UPD_DT
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE commission_payable_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO commission_payable_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM commission_payable_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_PAY_SEQ_CD) Then
                            .Append("COM_PAY_SEQ_CD")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_PAY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.POLICY_SEQ_CD) Then
                            .Append("POLICY_SEQ_CD")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.POLICY_SEQ_CD

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.PAYMENT_SEQ_CD) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.PAYMENT_SEQ_CD

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.ADVISOR_CD) Then
                            .Append("ADVISOR_CD")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.ADVISOR_CD

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_DT) Then
                            .Append("COM_DT")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_DT

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_RATE) Then
                            .Append("COM_RATE")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_RATE

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_AMT) Then
                            .Append("COM_AMT")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_AMT

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_CURR_CD) Then
                            .Append("COM_CURR_CD")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_CURR_CD

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.CONV_RATE) Then
                            .Append("CONV_RATE")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.CONV_RATE

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.CONV_COM_AMT) Then
                            .Append("CONV_COM_AMT")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.CONV_COM_AMT

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.CONV_CURR_CD) Then
                            .Append("CONV_CURR_CD")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.CONV_CURR_CD

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_REC_RATE) Then
                            .Append("COM_REC_RATE")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_REC_RATE

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_REC_AMT) Then
                            .Append("COM_REC_AMT")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_REC_AMT

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_TYPE) Then
                            .Append("COM_TYPE")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_TYPE

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_ST) Then
                            .Append("COM_ST")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_ST

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_CREA_BY) Then
                            .Append("COM_CREA_BY")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_CREA_BY

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_CREA_DT) Then
                            .Append("COM_CREA_DT")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_CREA_DT

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_LAST_UPD_BY) Then
                            .Append("COM_LAST_UPD_BY")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_LAST_UPD_BY

                        ElseIf CheckBit(shrtFlag, COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_LAST_UPD_DT) Then
                            .Append("COM_LAST_UPD_DT")
                            shrtFlag -= COMMISSION_PAYABLE_DTL_VO.Enum_commission_payable_dtl.COM_LAST_UPD_DT

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As commission_payable_dtl_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As commission_payable_dtl_VO.Enum_commission_payable_dtl = commission_payable_dtl_VO.Enum_commission_payable_dtl.None)
            With Command.Parameters
                If Not isnothing(Value.COM_PAY_SEQ_CD) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_PAY_SEQ_CD) Then .AddWithValue("@com_pay_seq_cd", Value.COM_PAY_SEQ_CD)
                If Not isnothing(Value.POLICY_SEQ_CD) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.POLICY_SEQ_CD) Then .AddWithValue("@policy_seq_cd", Value.POLICY_SEQ_CD)
                If Not isnothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.PAYMENT_SEQ_CD) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not isnothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.ADVISOR_CD) Then .AddWithValue("@advisor_cd", Value.ADVISOR_CD)
                If Year(Value.COM_DT) > 1 And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_DT) Then .AddWithValue("@com_dt", Value.COM_DT)
                If Value.COM_RATE >= 0 And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_RATE) Then .AddWithValue("@com_rate", Value.COM_RATE)
                If Value.COM_AMT >= 0 And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_AMT) Then .AddWithValue("@com_amt", Value.COM_AMT)
                If Not isnothing(Value.COM_CURR_CD) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_CURR_CD) Then .AddWithValue("@com_curr_cd", Value.COM_CURR_CD)
                If Value.CONV_RATE >= 0 And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.CONV_RATE) Then .AddWithValue("@conv_rate", Value.CONV_RATE)
                If Value.CONV_COM_AMT >= 0 And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.CONV_COM_AMT) Then .AddWithValue("@conv_com_amt", Value.CONV_COM_AMT)
                If Not isnothing(Value.CONV_CURR_CD) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.CONV_CURR_CD) Then .AddWithValue("@conv_curr_cd", Value.CONV_CURR_CD)
                If Value.COM_REC_RATE >= 0 And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_REC_RATE) Then .AddWithValue("@com_rec_rate", Value.COM_REC_RATE)
                If Value.COM_REC_AMT >= 0 And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_REC_AMT) Then .AddWithValue("@com_rec_amt", Value.COM_REC_AMT)
                If Not isnothing(Value.COM_TYPE) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_TYPE) Then .AddWithValue("@com_type", Value.COM_TYPE)
                If Not isnothing(Value.COM_ST) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_ST) Then .AddWithValue("@com_st", Value.COM_ST)
                If Not isnothing(Value.COM_CREA_BY) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_CREA_BY) Then .AddWithValue("@com_crea_by", Value.COM_CREA_BY)
                If Year(Value.COM_CREA_DT) > 1 And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_CREA_DT) Then .AddWithValue("@com_crea_dt", Value.COM_CREA_DT)
                If Not isnothing(Value.COM_LAST_UPD_BY) And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_LAST_UPD_BY) Then .AddWithValue("@com_last_upd_by", Value.COM_LAST_UPD_BY)
                If Year(Value.COM_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, commission_payable_dtl_VO.Enum_commission_payable_dtl.COM_LAST_UPD_DT) Then .AddWithValue("@com_last_upd_dt", Value.COM_LAST_UPD_DT)
            End With
        End Sub
        Public Function GetQuery(ByVal Value As commission_payable_dtl_VO, Optional ByVal ExcludeValue As commission_payable_dtl_VO.Enum_commission_payable_dtl = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM commission_payable_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "risk_profile_mstr"
    <Serializable()> _
    Public Class RISK_PROFILE_MSTR_VO

        Public RISK_PROFILE_CD As String
        Public RISK_PROFILE_DESC As String
        Public RISK_PROFILE_CREA_BY As String
        Public RISK_PROFILE_CREA_DT As Date
        Public RISK_PROFILE_LAST_UPD_BY As String
        Public RISK_PROFILE_LAST_UPD_DT As Date

        Public Enum Enum_RISK_PROFILE_MSTR As Short
            NONE = 0
            risk_profile_cd = 1
            risk_profile_desc = 2
            risk_profile_crea_by = 4
            risk_profile_crea_dt = 8
            risk_profile_last_upd_by = 16
            risk_profile_last_upd_dt = 32
        End Enum

    End Class

    Public Class RISK_PROFILE_MSTR_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As RISK_PROFILE_MSTR_VO, Optional ByVal ExcludeValue As RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM RISK_PROFILE_MSTR " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As RISK_PROFILE_MSTR_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR = RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.RISK_PROFILE_CD) Then shrtFlag += RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_cd
                If Not IsNothing(.RISK_PROFILE_DESC) Then shrtFlag += RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_desc
                If Not IsNothing(.RISK_PROFILE_CREA_BY) Then shrtFlag += RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_crea_by
                If Year(.RISK_PROFILE_CREA_DT) > 1 Then shrtFlag += RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_crea_dt
                If Not IsNothing(.RISK_PROFILE_LAST_UPD_BY) Then shrtFlag += RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_last_upd_by
                If Year(.RISK_PROFILE_LAST_UPD_DT) > 1 Then shrtFlag += RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE RISK_PROFILE_MSTR SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO RISK_PROFILE_MSTR (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM RISK_PROFILE_MSTR WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_cd) Then
                            .Append("RISK_PROFILE_CD")
                            shrtFlag -= RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_cd

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_desc) Then
                            .Append("RISK_PROFILE_DESC")
                            shrtFlag -= RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_desc

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_crea_by) Then
                            .Append("RISK_PROFILE_CREA_BY")
                            shrtFlag -= RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_crea_by

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_crea_dt) Then
                            .Append("RISK_PROFILE_CREA_DT")
                            shrtFlag -= RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_crea_dt

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_last_upd_by) Then
                            .Append("RISK_PROFILE_LAST_UPD_BY")
                            shrtFlag -= RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_last_upd_by

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_last_upd_dt) Then
                            .Append("RISK_PROFILE_LAST_UPD_DT")
                            shrtFlag -= RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As RISK_PROFILE_MSTR_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR = RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.NONE)
            With Command.Parameters
                If Not IsNothing(Value.RISK_PROFILE_CD) And Not CheckBit(ExcludeValue, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_cd) Then .AddWithValue("@risk_profile_cd", Value.RISK_PROFILE_CD)
                If Not IsNothing(Value.RISK_PROFILE_DESC) And Not CheckBit(ExcludeValue, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_desc) Then .AddWithValue("@risk_profile_desc", Value.RISK_PROFILE_DESC)
                If Not IsNothing(Value.RISK_PROFILE_CREA_BY) And Not CheckBit(ExcludeValue, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_crea_by) Then .AddWithValue("@risk_profile_crea_by", Value.RISK_PROFILE_CREA_BY)
                If Year(Value.RISK_PROFILE_CREA_DT) > 1 And Not CheckBit(ExcludeValue, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_crea_dt) Then .AddWithValue("@risk_profile_crea_dt", Value.RISK_PROFILE_CREA_DT)
                If Not IsNothing(Value.RISK_PROFILE_LAST_UPD_BY) And Not CheckBit(ExcludeValue, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_last_upd_by) Then .AddWithValue("@risk_profile_last_upd_by", Value.RISK_PROFILE_LAST_UPD_BY)
                If Year(Value.RISK_PROFILE_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, RISK_PROFILE_MSTR_VO.Enum_RISK_PROFILE_MSTR.risk_profile_last_upd_dt) Then .AddWithValue("@risk_profile_last_upd_dt", Value.RISK_PROFILE_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "risk_profile_dtl"
    <Serializable()> _
    Public Class RISK_PROFILE_DTL_VO

        Public RISK_DTL_CD As String
        Public RISK_PROFILE_CD As String
        Public RISK_DTL_DESC As String
        Public RISK_DTL_CREA_BY As String
        Public RISK_DTL_CREA_DT As Date
        Public RISK_DTL_LAST_UPD_BY As String
        Public RISK_DTL_LAST_UPD_DT As Date

        Public Enum Enum_RISK_PROFILE_DTL As Short
            NONE = 0
            risk_dtl_cd = 1
            risk_profile_cd = 2
            risk_dtl_desc = 4
            risk_dtl_crea_by = 8
            risk_dtl_crea_dt = 16
            risk_dtl_last_upd_by = 32
            risk_dtl_last_upd_dt = 64
        End Enum

    End Class

    Public Class RISK_PROFILE_DTL_DAO
        Inherits CommonDAO

        Public Function Search(ByVal Value As RISK_PROFILE_DTL_VO, Optional ByVal ExcludeValue As RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM RISK_PROFILE_DTL " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As RISK_PROFILE_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL = RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.RISK_DTL_CD) Then shrtFlag += RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_cd
                If Not IsNothing(.RISK_PROFILE_CD) Then shrtFlag += RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_profile_cd
                If Not IsNothing(.RISK_DTL_DESC) Then shrtFlag += RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_desc
                If Not IsNothing(.RISK_DTL_CREA_BY) Then shrtFlag += RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_crea_by
                If Year(.RISK_DTL_CREA_DT) > 1 Then shrtFlag += RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_crea_dt
                If Not IsNothing(.RISK_DTL_LAST_UPD_BY) Then shrtFlag += RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_last_upd_by
                If Year(.RISK_DTL_LAST_UPD_DT) > 1 Then shrtFlag += RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE RISK_PROFILE_DTL SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO RISK_PROFILE_DTL (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM RISK_PROFILE_DTL WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_cd) Then
                            .Append("RISK_DTL_CD")
                            shrtFlag -= RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_cd

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_profile_cd) Then
                            .Append("RISK_PROFILE_CD")
                            shrtFlag -= RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_profile_cd

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_desc) Then
                            .Append("RISK_DTL_DESC")
                            shrtFlag -= RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_desc

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_crea_by) Then
                            .Append("RISK_DTL_CREA_BY")
                            shrtFlag -= RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_crea_by

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_crea_dt) Then
                            .Append("RISK_DTL_CREA_DT")
                            shrtFlag -= RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_crea_dt

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_last_upd_by) Then
                            .Append("RISK_DTL_LAST_UPD_BY")
                            shrtFlag -= RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_last_upd_by

                        ElseIf CheckBit(shrtFlag, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_last_upd_dt) Then
                            .Append("RISK_DTL_LAST_UPD_DT")
                            shrtFlag -= RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As RISK_PROFILE_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL = RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.RISK_DTL_CD) And Not CheckBit(ExcludeValue, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_cd) Then .AddWithValue("@risk_dtl_cd", Value.RISK_DTL_CD)
                If Not IsNothing(Value.RISK_PROFILE_CD) And Not CheckBit(ExcludeValue, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_profile_cd) Then .AddWithValue("@risk_profile_cd", Value.RISK_PROFILE_CD)
                If Not IsNothing(Value.RISK_DTL_DESC) And Not CheckBit(ExcludeValue, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_desc) Then .AddWithValue("@risk_dtl_desc", Value.RISK_DTL_DESC)
                If Not IsNothing(Value.RISK_DTL_CREA_BY) And Not CheckBit(ExcludeValue, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_crea_by) Then .AddWithValue("@risk_dtl_crea_by", Value.RISK_DTL_CREA_BY)
                If Year(Value.RISK_DTL_CREA_DT) > 1 And Not CheckBit(ExcludeValue, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_crea_dt) Then .AddWithValue("@risk_dtl_crea_dt", Value.RISK_DTL_CREA_DT)
                If Not IsNothing(Value.RISK_DTL_LAST_UPD_BY) And Not CheckBit(ExcludeValue, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_last_upd_by) Then .AddWithValue("@risk_dtl_last_upd_by", Value.RISK_DTL_LAST_UPD_BY)
                If Year(Value.RISK_DTL_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, RISK_PROFILE_DTL_VO.Enum_RISK_PROFILE_DTL.risk_dtl_last_upd_dt) Then .AddWithValue("@risk_dtl_last_upd_dt", Value.RISK_DTL_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "user_mstr"
    <Serializable()> _
    Public Class USER_MSTR_VO_PASSWORD

        Public USER_NAME As String
        Public USER_PASSWORD As String
        Public USER_LAST_UPD_BY As String
        Public USER_LAST_UPD_DT As Date

        Public Enum Enum_USER_MSTR_PASSWORD As Short
            NONE = 0
            user_name = 1
            user_password = 2
            user_last_upd_by = 4
            user_last_upd_dt = 8
        End Enum

    End Class

    Public Class USER_MSTR_DAO_PASSWORD
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As USER_MSTR_VO_PASSWORD) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_user_mstr_ins_PASSWORD"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As USER_MSTR_VO_PASSWORD) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As USER_MSTR_VO_PASSWORD) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_user_mstr_upd_PASSWORD"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As USER_MSTR_VO_PASSWORD, Optional ByVal ExcludeValue As USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM USER_MSTR " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As USER_MSTR_VO_PASSWORD, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD = USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Integer

            With Value
                If Not IsNothing(.USER_NAME) Then shrtFlag += USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_name
                If Not IsNothing(.USER_PASSWORD) Then shrtFlag += USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_password
                If Not IsNothing(.USER_LAST_UPD_BY) Then shrtFlag += USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_last_upd_by
                If Year(.USER_LAST_UPD_DT) > 1 Then shrtFlag += USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE USER_MSTR SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO USER_MSTR (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM USER_MSTR WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_name) Then
                            .Append("USER_NAME")
                            shrtFlag -= USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_name

                        ElseIf CheckBit(shrtFlag, USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_password) Then
                            .Append("USER_PASSWORD")
                            shrtFlag -= USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_password

                        ElseIf CheckBit(shrtFlag, USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_last_upd_by) Then
                            .Append("USER_LAST_UPD_BY")
                            shrtFlag -= USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_last_upd_by

                        ElseIf CheckBit(shrtFlag, USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_last_upd_dt) Then
                            .Append("USER_LAST_UPD_DT")
                            shrtFlag -= USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" And ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As USER_MSTR_VO_PASSWORD, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD = USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.NONE)
            With Command.Parameters
                If Not IsNothing(Value.USER_NAME) And Not CheckBit(ExcludeValue, USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_name) Then .AddWithValue("@user_name", Value.USER_NAME)
                If Not IsNothing(Value.USER_PASSWORD) And Not CheckBit(ExcludeValue, USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_password) Then .AddWithValue("@user_password", Value.USER_PASSWORD)
                If Not IsNothing(Value.USER_LAST_UPD_BY) And Not CheckBit(ExcludeValue, USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_last_upd_by) Then .AddWithValue("@user_last_upd_by", Value.USER_LAST_UPD_BY)
                If Year(Value.USER_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, USER_MSTR_VO_PASSWORD.Enum_USER_MSTR_PASSWORD.user_last_upd_dt) Then .AddWithValue("@user_last_upd_dt", Value.USER_LAST_UPD_DT)
            End With
        End Sub
    End Class

#End Region

#Region "user_cash_advance_mstr"

    <Serializable()> _
    Public Class USER_CASH_ADVANCE_MSTR_VO

        Public CASH_ADV_SEQ_CD As String
        Public ADVISOR_CD As String
        Public CASH_ADV_DT As Date
        Public CASH_ADV_AMT As Integer = -1
        Public CASH_ADV_CURR_CD As String
        Public CASH_ADV_CREA_BY As String
        Public CASH_ADV_CREA_DT As Date
        Public CASH_ADV_LAST_UPD_BY As String
        Public CASH_ADV_LAST_UPD_DT As Date

        Public Enum Enum_USER_CASH_ADVANCE_MSTR As Short
            NONE = 0
            cash_adv_seq_cd = 1
            advisor_cd = 2
            cash_adv_dt = 4
            cash_adv_amt = 8
            cash_adv_curr_cd = 16
            cash_adv_crea_by = 32
            cash_adv_crea_dt = 64
            cash_adv_last_upd_by = 128
            cash_adv_last_upd_dt = 256
        End Enum

    End Class

    Public Class USER_CASH_ADVANCE_MSTR_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As USER_CASH_ADVANCE_MSTR_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_user_cash_advance_mstr_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As USER_CASH_ADVANCE_MSTR_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As USER_CASH_ADVANCE_MSTR_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_user_cash_advance_mstr_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As USER_CASH_ADVANCE_MSTR_VO, Optional ByVal ExcludeValue As USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM user_cash_advance_mstr " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As USER_CASH_ADVANCE_MSTR_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR = USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.CASH_ADV_SEQ_CD) Then shrtFlag += USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_seq_cd
                If Not IsNothing(.ADVISOR_CD) Then shrtFlag += USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.advisor_cd
                If Year(.CASH_ADV_DT) > 1 Then shrtFlag += USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_dt
                If .CASH_ADV_AMT >= 0 Then shrtFlag += USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_amt
                If Not IsNothing(.CASH_ADV_CURR_CD) Then shrtFlag += USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_curr_cd
                If Not IsNothing(.CASH_ADV_CREA_BY) Then shrtFlag += USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_by
                If Year(.CASH_ADV_CREA_DT) > 1 Then shrtFlag += USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_dt
                If Not IsNothing(.CASH_ADV_LAST_UPD_BY) Then shrtFlag += USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_by
                If Year(.CASH_ADV_LAST_UPD_DT) > 1 Then shrtFlag += USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_dt
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE user_cash_advance_mstr SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO user_cash_advance_mstr (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM user_cash_advance_mstr WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_seq_cd) Then
                            .Append("CASH_ADV_SEQ_CD")
                            shrtFlag -= USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_seq_cd

                        ElseIf CheckBit(shrtFlag, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.advisor_cd) Then
                            .Append("ADVISOR_CD")
                            shrtFlag -= USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.advisor_cd

                        ElseIf CheckBit(shrtFlag, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_dt) Then
                            .Append("CASH_ADV_DT")
                            shrtFlag -= USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_dt

                        ElseIf CheckBit(shrtFlag, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_amt) Then
                            .Append("CASH_ADV_AMT")
                            shrtFlag -= USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_amt

                        ElseIf CheckBit(shrtFlag, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_curr_cd) Then
                            .Append("CASH_ADV_CURR_CD")
                            shrtFlag -= USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_curr_cd

                        ElseIf CheckBit(shrtFlag, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_by) Then
                            .Append("CASH_ADV_CREA_BY")
                            shrtFlag -= USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_by

                        ElseIf CheckBit(shrtFlag, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_dt) Then
                            .Append("CASH_ADV_CREA_DT")
                            shrtFlag -= USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_dt

                        ElseIf CheckBit(shrtFlag, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_by) Then
                            .Append("CASH_ADV_LAST_UPD_BY")
                            shrtFlag -= USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_by

                        ElseIf CheckBit(shrtFlag, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_dt) Then
                            .Append("CASH_ADV_LAST_UPD_DT")
                            shrtFlag -= USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_dt

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As USER_CASH_ADVANCE_MSTR_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR = USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.NONE)
            With Command.Parameters
                If Not IsNothing(Value.CASH_ADV_SEQ_CD) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_seq_cd) Then .AddWithValue("@cash_adv_seq_cd", Value.CASH_ADV_SEQ_CD)
                If Not IsNothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.advisor_cd) Then .AddWithValue("@advisor_cd", Value.ADVISOR_CD)
                If Year(Value.CASH_ADV_DT) > 1 And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_dt) Then .AddWithValue("@cash_adv_dt", Value.CASH_ADV_DT)
                If Value.CASH_ADV_AMT >= 0 And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_amt) Then .AddWithValue("@cash_adv_amt", Value.CASH_ADV_AMT)
                If Not IsNothing(Value.CASH_ADV_CURR_CD) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_curr_cd) Then .AddWithValue("@cash_adv_curr_cd", Value.CASH_ADV_CURR_CD)
                If Not IsNothing(Value.CASH_ADV_CREA_BY) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_by) Then .AddWithValue("@cash_adv_crea_by", Value.CASH_ADV_CREA_BY)
                If Year(Value.CASH_ADV_CREA_DT) > 1 And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_dt) Then .AddWithValue("@cash_adv_crea_dt", Value.CASH_ADV_CREA_DT)
                If Not IsNothing(Value.CASH_ADV_LAST_UPD_BY) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_by) Then .AddWithValue("@cash_adv_last_upd_by", Value.CASH_ADV_LAST_UPD_BY)
                If Year(Value.CASH_ADV_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_dt) Then .AddWithValue("@cash_adv_last_upd_dt", Value.CASH_ADV_LAST_UPD_DT)
            End With
        End Sub
        Public Sub ParamDSBuilder(ByRef Command As SqlDataSource, ByVal Value As USER_CASH_ADVANCE_MSTR_VO, Optional ByVal ExcludeValue As USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR = USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.NONE)
            Dim QueryType As QueryType = 0
            Command.SelectParameters.Clear()
            With Command.SelectParameters
                If Not IsNothing(Value.CASH_ADV_SEQ_CD) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_seq_cd) Then .Add("@cash_adv_seq_cd", Value.CASH_ADV_SEQ_CD)
                If Not IsNothing(Value.ADVISOR_CD) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.advisor_cd) Then .Add("@advisor_cd", Value.ADVISOR_CD)
                If Year(Value.CASH_ADV_DT) > 1 And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_dt) Then .Add("@cash_adv_dt", Value.CASH_ADV_DT)
                If Value.CASH_ADV_AMT >= 0 And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_amt) Then .Add("@cash_adv_amt", Value.CASH_ADV_AMT)
                If Not IsNothing(Value.CASH_ADV_CURR_CD) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_curr_cd) Then .Add("@cash_adv_curr_cd", Value.CASH_ADV_CURR_CD)
                If Not IsNothing(Value.CASH_ADV_CREA_BY) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_by) Then .Add("@cash_adv_crea_by", Value.CASH_ADV_CREA_BY)
                If Year(Value.CASH_ADV_CREA_DT) > 1 And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_crea_dt) Then .Add("@cash_adv_crea_dt", Value.CASH_ADV_CREA_DT)
                If Not IsNothing(Value.CASH_ADV_LAST_UPD_BY) And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_by) Then .Add("@cash_adv_last_upd_by", Value.CASH_ADV_LAST_UPD_BY)
                If Year(Value.CASH_ADV_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR.cash_adv_last_upd_dt) Then .Add("@cash_adv_last_upd_dt", Value.CASH_ADV_LAST_UPD_DT)
            End With
        End Sub

        Public Function GetQuery(ByVal Value As USER_CASH_ADVANCE_MSTR_VO, Optional ByVal ExcludeValue As USER_CASH_ADVANCE_MSTR_VO.Enum_USER_CASH_ADVANCE_MSTR = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM user_cash_advance_mstr " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "ar_type_mstr"

    <Serializable()> _
    Public Class AR_TYPE_MSTR_VO

        Public AR_TYPE_SEQ_CD As String
        Public AR_TYPE_DESC As String
        Public AR_TYPE_START_NO As Integer = -1
        Public AR_TYPE_CURR_NO As Long = -1
        Public AR_TYPE_LAST_UPD_BY As String
        Public AR_TYPE_LAST_UPD_DT As Date

        Public Enum Enum_AR_TYPE_MSTR As Short
            NONE = 0
            ar_type_seq_cd = 1
            ar_type_desc = 2
            ar_type_start_no = 4
            ar_type_curr_no = 8
            ar_type_last_upd_by = 16
            ar_type_last_upd_dt = 32
        End Enum

    End Class

    Public Class AR_TYPE_MSTR_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As ar_type_mstr_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_ar_type_mstr_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As ar_type_mstr_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As ar_type_mstr_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OLEDBCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_ar_type_mstr_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As ar_type_mstr_VO, Optional ByVal ExcludeValue As ar_type_mstr_VO.Enum_ar_type_mstr = 0, Optional ByVal SQLLike As Boolean = False) As Data.Datatable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OLEDBCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM ar_type_mstr " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As AR_TYPE_MSTR_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As AR_TYPE_MSTR_VO.Enum_ar_type_mstr = AR_TYPE_MSTR_VO.Enum_ar_type_mstr.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not isnothing(.AR_TYPE_SEQ_CD) Then shrtFlag += AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_SEQ_CD
                If Not isnothing(.AR_TYPE_DESC) Then shrtFlag += AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_DESC
                If .AR_TYPE_START_NO >= 0 Then shrtFlag += AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_START_NO
                If .AR_TYPE_CURR_NO >= 0 Then shrtFlag += AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_CURR_NO
                If Not isnothing(.AR_TYPE_LAST_UPD_BY) Then shrtFlag += AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_LAST_UPD_BY
                If Year(.AR_TYPE_LAST_UPD_DT) > 1 Then shrtFlag += AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_LAST_UPD_DT
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> AR_TYPE_MSTR_VO.Enum_ar_type_mstr.None Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE ar_type_mstr SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO ar_type_mstr (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM ar_type_mstr WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_SEQ_CD) Then
                            .Append("AR_TYPE_SEQ_CD")
                            shrtFlag -= AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_SEQ_CD

                        ElseIf CheckBit(shrtFlag, AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_DESC) Then
                            .Append("AR_TYPE_DESC")
                            shrtFlag -= AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_DESC

                        ElseIf CheckBit(shrtFlag, AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_START_NO) Then
                            .Append("AR_TYPE_START_NO")
                            shrtFlag -= AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_START_NO

                        ElseIf CheckBit(shrtFlag, AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_CURR_NO) Then
                            .Append("AR_TYPE_CURR_NO")
                            shrtFlag -= AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_CURR_NO

                        ElseIf CheckBit(shrtFlag, AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_LAST_UPD_BY) Then
                            .Append("AR_TYPE_LAST_UPD_BY")
                            shrtFlag -= AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_LAST_UPD_BY

                        ElseIf CheckBit(shrtFlag, AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_LAST_UPD_DT) Then
                            .Append("AR_TYPE_LAST_UPD_DT")
                            shrtFlag -= AR_TYPE_MSTR_VO.Enum_ar_type_mstr.AR_TYPE_LAST_UPD_DT

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OLEDBCommand, ByVal Value As ar_type_mstr_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As ar_type_mstr_VO.Enum_ar_type_mstr = ar_type_mstr_VO.Enum_ar_type_mstr.None)
            With Command.Parameters
                If Not isnothing(Value.AR_TYPE_SEQ_CD) And Not CheckBit(ExcludeValue, ar_type_mstr_VO.Enum_ar_type_mstr.AR_TYPE_SEQ_CD) Then .AddWithValue("@ar_type_seq_cd", Value.AR_TYPE_SEQ_CD)
                If Not isnothing(Value.AR_TYPE_DESC) And Not CheckBit(ExcludeValue, ar_type_mstr_VO.Enum_ar_type_mstr.AR_TYPE_DESC) Then .AddWithValue("@ar_type_desc", Value.AR_TYPE_DESC)
                If Value.AR_TYPE_START_NO >= 0 And Not CheckBit(ExcludeValue, ar_type_mstr_VO.Enum_ar_type_mstr.AR_TYPE_START_NO) Then .AddWithValue("@ar_type_start_no", Value.AR_TYPE_START_NO)
                If Value.AR_TYPE_CURR_NO >= 0 And Not CheckBit(ExcludeValue, ar_type_mstr_VO.Enum_ar_type_mstr.AR_TYPE_CURR_NO) Then .AddWithValue("@ar_type_curr_no", Value.AR_TYPE_CURR_NO)
                If Not isnothing(Value.AR_TYPE_LAST_UPD_BY) And Not CheckBit(ExcludeValue, ar_type_mstr_VO.Enum_ar_type_mstr.AR_TYPE_LAST_UPD_BY) Then .AddWithValue("@ar_type_last_upd_by", Value.AR_TYPE_LAST_UPD_BY)
                If Year(Value.AR_TYPE_LAST_UPD_DT) > 1 And Not CheckBit(ExcludeValue, ar_type_mstr_VO.Enum_ar_type_mstr.AR_TYPE_LAST_UPD_DT) Then .AddWithValue("@ar_type_last_upd_dt", Value.AR_TYPE_LAST_UPD_DT)
            End With
        End Sub
        Public Function GetQuery(ByVal Value As ar_type_mstr_VO, Optional ByVal ExcludeValue As ar_type_mstr_VO.Enum_ar_type_mstr = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM ar_type_mstr " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

#Region "ar_type_payment_dtl"

    <Serializable()> _
    Public Class AR_TYPE_PAYMENT_DTL_VO

        Public PAYMENT_SEQ_CD As String
        Public AR_TYPE_SEQ_CD As String

        Public Enum Enum_AR_TYPE_PAYMENT_DTL As Short
            NONE = 0
            payment_seq_cd = 1
            ar_type_seq_cd = 2
        End Enum

    End Class

    Public Class AR_TYPE_PAYMENT_DTL_DAO
        Inherits CommonDAO

        Public Function Create_Record(ByVal Value As AR_TYPE_PAYMENT_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = "sp_ar_type_payment_dtl_ins"
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.InsertType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Function Delete(ByVal Value As AR_TYPE_PAYMENT_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandText = QueryBuilder(Value, QueryType.DeleteType)
                End With

                'Dynamic Param Build up
                Call ParamBuilder(cmdData, Value, QueryType.DeleteType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)
                If IsNothing(Me.Transaction) Then txnData.Rollback()
                Throw ex

            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try
            Return blnSuccess

        End Function

        Public Overloads Function Update(ByVal Value As AR_TYPE_PAYMENT_DTL_VO) As Boolean
            Dim daoMain As New Polydao.Common
            Dim cnnServer As New OleDbConnection
            Dim txnData As OleDbTransaction
            Dim blnSuccess As Boolean

            Try
                If IsNothing(Me.Transaction) Then
                    daoMain.ConnectionString = Me.ConnectionString
                    txnData = daoMain.OpenConnection(cnnServer)
                Else
                    txnData = Me.Transaction
                End If

                Dim cmdData As New OleDbCommand
                Dim sbQuery As New StringBuilder

                With cmdData
                    .Connection = txnData.Connection
                    .Transaction = txnData
                    .CommandType = CommandType.StoredProcedure
                    .CommandText = " sp_ar_type_payment_dtl_upd"
                End With

                Call ParamBuilder(cmdData, Value, QueryType.UpdateType)

                daoMain.UpdateData(cmdData)

                If IsNothing(Me.Transaction) Then txnData.Commit()
                blnSuccess = True

            Catch ex As Exception
                Debug.WriteLine(ex.Message)

                If IsNothing(Me.Transaction) Then txnData.Rollback()

                Throw ex
            Finally
                If IsNothing(Me.Transaction) Then daoMain.CloseConnection(cnnServer)

            End Try

            Return blnSuccess
        End Function

        Public Function Search(ByVal Value As AR_TYPE_PAYMENT_DTL_VO, Optional ByVal ExcludeValue As AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL = 0, Optional ByVal SQLLike As Boolean = False) As Data.DataTable
            Dim daoMain As New Polydao.Common
            Dim cnnSearch As New OleDbConnection
            Dim dtSearch As New Data.DataTable

            Try
                daoMain.ConnectionString = Me.ConnectionString
                cnnSearch = daoMain.OpenConnection

                Dim cmdSearch As New OleDbCommand

                With cmdSearch
                    .Connection = cnnSearch
                    .CommandText = "SELECT * FROM ar_type_payment_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
                End With

                Call ParamBuilder(cmdSearch, Value, ExcludeValue)

                Dim daSearch As New OleDbDataAdapter(cmdSearch)

                daSearch.Fill(dtSearch)

            Catch ex As Exception

                Debug.WriteLine(ex.Message)

            Finally
                daoMain.CloseConnection(cnnSearch)

            End Try

            Return dtSearch
        End Function

        Private Function QueryBuilder(ByVal Value As AR_TYPE_PAYMENT_DTL_VO, Optional ByVal QueryType As QueryType = 0, _
         Optional ByVal ExcludeFlag As AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL = AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.NONE, Optional ByVal TableAlias As String = "", Optional ByVal SQLLike As Boolean = False, _
         Optional ByVal IncludeBlanks As Boolean = True) As String

            Dim sbQuery As New StringBuilder
            Dim shrtFlag As Short

            With Value
                If Not IsNothing(.PAYMENT_SEQ_CD) Then shrtFlag += AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.payment_seq_cd
                If Not IsNothing(.AR_TYPE_SEQ_CD) Then shrtFlag += AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.ar_type_seq_cd
            End With
            If shrtFlag <> 0 Then
                Dim bytCount As Byte

                If ExcludeFlag <> AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.NONE Then shrtFlag -= ExcludeFlag
                With sbQuery

                    Select Case QueryType
                        Case QueryType.SelectType  ' Where
                            .Append("WHERE ")
                        Case QueryType.UpdateType  'Update
                            .Append("UPDATE ar_type_payment_dtl SET ")
                        Case QueryType.InsertType  'Insert
                            .Append("INSERT INTO ar_type_payment_dtl (")
                        Case QueryType.DeleteType   'Delete
                            .Append("DELETE FROM ar_type_payment_dtl WHERE ")
                    End Select

                    Do While shrtFlag > 0
                        If CheckBit(shrtFlag, AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.payment_seq_cd) Then
                            .Append("PAYMENT_SEQ_CD")
                            shrtFlag -= AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.payment_seq_cd

                        ElseIf CheckBit(shrtFlag, AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.ar_type_seq_cd) Then
                            .Append("AR_TYPE_SEQ_CD")
                            shrtFlag -= AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.ar_type_seq_cd

                        End If

                        Select Case QueryType
                            Case QueryType.SelectType, QueryType.DeleteType  ' Where Clause
                                Select Case SQLLike
                                    Case False
                                        .Append(" = ? AND ")

                                    Case True
                                        .Append(" LIKE ? AND ")

                                End Select

                            Case QueryType.UpdateType  ' Update
                                .Append(" = ?, ")

                            Case QueryType.InsertType  ' Insert
                                .Append(", ")
                                bytCount += 1

                            Case Else 'bypass
                                .Append(" AND ")
                                QueryType = 0

                        End Select
                    Loop

                    Select Case QueryType
                        Case QueryType.SelectType, QueryType.DeleteType  'Where Clause
                            .Replace(" AND ", "", .Length - 6, 6)
                            .Append(";")

                        Case QueryType.UpdateType   ' Update
                            .Replace("?, ", "? ", .Length - 3, 3)

                        Case QueryType.InsertType  ' Insert
                            .Replace(", ", ") VALUES (", .Length - 2, 2)
                            .Append("#", bytCount)
                            .Replace("#", "?,")
                            .Replace("?,", "?);", .Length - 2, 2)
                    End Select
                End With
            End If
            Return sbQuery.ToString
        End Function

        Private Sub ParamBuilder(ByRef Command As OleDbCommand, ByVal Value As AR_TYPE_PAYMENT_DTL_VO, Optional ByVal QueryType As QueryType = 0, Optional ByVal ExcludeValue As AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL = AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.NONE)
            With Command.Parameters
                If Not IsNothing(Value.PAYMENT_SEQ_CD) And Not CheckBit(ExcludeValue, AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.payment_seq_cd) Then .AddWithValue("@payment_seq_cd", Value.PAYMENT_SEQ_CD)
                If Not IsNothing(Value.AR_TYPE_SEQ_CD) And Not CheckBit(ExcludeValue, AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL.ar_type_seq_cd) Then .AddWithValue("@ar_type_seq_cd", Value.AR_TYPE_SEQ_CD)
            End With
        End Sub
        Public Function GetQuery(ByVal Value As AR_TYPE_PAYMENT_DTL_VO, Optional ByVal ExcludeValue As AR_TYPE_PAYMENT_DTL_VO.Enum_AR_TYPE_PAYMENT_DTL = 0, Optional ByVal SQLLike As Boolean = False) As String
            Dim strReturn As String = "SELECT * FROM ar_type_payment_dtl " & QueryBuilder(Value, QueryType.SelectType, ExcludeValue, , SQLLike)
            Return strReturn
        End Function

    End Class

#End Region

End Namespace